Detecting the type of iPhone interrupt

女生的网名这么多〃 提交于 2019-11-28 11:14:16
benzado

That information is probably not available to your app, but here's some things to try.

  1. In applicationWillResignActive:, check the NSNotification's object and userInfo properties to see if there are any hints there.

  2. Register to receive all notifications posted to the default notification center:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:nil object:nil];
    

Your method will be called when anything is posted. Log the notification object and userInfo dictionary and maybe you will see a useful notification being posted. If you find one, you can register just for that.

  1. This is the most hacky, but you might be able to get access to the alert that is displayed if it is a message or battery warning. Alerts are displayed in a UIWindow over your app's main UIWindow. You could register for UIWindowDidBecomeVisibleNotification, then look at the window's subviews to see if you can find an alert or some other useful clue.

All of the above methods would be relying on undocumented behavior to work, and could possibly get your submission rejected from the App Store. None of them involve private method calls, though you could argue that observing an undocumented notification name counts as private API. In the end, Apple's opinion is the only one that will matter.

Personally, I'd try it, making sure the code fails gracefully if and when the system changes.

Use an audio session?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!