iOS Detect system volume level change. private API or not? AVSystemController_SystemVolumeDidChangeNotification
Asked Answered
C

1

8

Can listening to AVSystemController_SystemVolumeDidChangeNotification NSNotification be considered (during the App Store review process) as using private API?

In my application I need to display and update the current volume level. Volume indicator should be updated after pressing hardware volume buttons and after volume change in MPVolumeView slider.

I've searched solution how to get notification or event of hardware volume button press and had found a number of solutions.

For example, iPhone Detect Volume Keys press.

and

How to get audio volume level, and volume changed notifications on iOS?

I like the solution with listening to NSNotificationCenter and it seems that the most simplest and clear solution is listening to AVSystemController_SystemVolumeDidChangeNotification (And it works fine)

But there are one important thing that I want to know for sure.

This notification name is not appearing in any official Apple documentation, and there are discussions about if this notification usage will be considered as "Using the private API" or not.

As I understand, using the private API is connected with calling private methods. Thats why using this notification key can not be considered as private API usage (because actually we are using notification name as NSString).

Maybe somebody knows this for sure, or have experience with usage of the AVSystemController_SystemVolumeDidChangeNotification and app was submitted/rejected?

Many thanks for any information!

Catchall answered 14/8, 2014 at 12:55 Comment(9)
If you'd like a documented solution, why not try key-value-observing on the audio session outputVolume property? Example shown here.Havens
Wow, perfect! Thank you so much, Nate! Works great in iOS 7 and I suggest that in iOS 6 too.Catchall
yes,you can .And my application now on the AppStore.Ortrud
@Havens That only works if the output volume is not at its max/min. If it is, the output volume is never modified and thus the observation never occurs.Jurkoic
@StephenPaul, if you use KVO, you would just read the property directly when your app starts. After that, KVO keeps you updated with changes.Havens
@Havens You completely blew right by my point. I'm aware that KVO keeps you updated on the changes. But the fact that it keeps you updated on the CHANGES is the problem. If the output volume never changes, aka if it is 0 and you try to lower the volume, the output volume never changes and you will never get that message.Jurkoic
@StephenPaul, the title of the question is "detect system volume level change". He clarifies that this is to display the volume level. Thus, if it doesn't change, he wouldn't need notification. Your point was not missed. It was a bad point.Havens
Hi guys, I've ended up with @Nate's solution, i'm just reading the value of AudioSession's outputVolume property if I need the value, and KVObserving it when I need notification about this property change. Works perfectly for displaying current system volume level in my custom UI. My final code: gist.github.com/tkach/f5403fa82d222a62379d6c6e4ad705a2Catchall
@Havens It's a bad point according to whom? It depends on who you're asking. The OP referred a stack overflow thread that dealt with detecting volume keys. How is what I said not relevant to that? Also, I wasn't disagreeing with your approach, as it is actually Apple's preferred approach, I was just explaining a situation that I myself have run into lately with that implementation that others may not be aware of. I'm sure other readers will benefit from that one line of insight.Jurkoic
E
0

I know an alternative method using KVO has been mentioned in the comments. The limitations of this method are also discussed in the comments. The original question though was about the experience of using the NSNotificationCenter and AVSystemController_SystemVolumeDidChangeNotification. I have used this method in my app and it didn't get rejected. It is available on App Store.

Ennead answered 3/12, 2018 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.