Can iOS receive broadcasts like Android?

谁说胖子不能爱 提交于 2019-12-19 08:10:11

问题


I would like my app to be informed when a headset/headphones is disconnected from an iOS device after a period of idle time long enough for the app to have been cleaned up (and thus might not be running) similar to how a BroadcastReceiver works in android. I suspect it's not possible but would appreciate any ideas.

I have looked into local and push notifications and the NSNotificationCenter. Push notifications aren't appropriate because events happen on the device. It only seems possible to schedule (by specifying a time) local notifications and not create them from system events and notifications from the NSNotificationCenter are only received when the app is running.

Have I misinterpreted any of the information above or is there another trick to use?


回答1:


Background processes and system event based broadcast receivers for an application that isn't running aren't possible in the current version (iOS 6) and any previous versions. There are no plans to make it possible that I have come across.

As stated in the question, it is possible to use the NSNotificationCenter to achieve a similar affect but only if events that trigger the notifications are external to the phone or the notifications can be triggered from predetermined time.



来源:https://stackoverflow.com/questions/10213125/can-ios-receive-broadcasts-like-android

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