iOS Detect system volume level change. private API

2019-04-23 07:22发布

问题:

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!

回答1:

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 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 the AppStore.