5

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?

rogermushroom
  • 5,486
  • 4
  • 42
  • 68
  • 2
    Have a look at this post [Can't get a notification when connecting an external accessory to the 3.5 mm headphones jack][1] [1]: http://stackoverflow.com/questions/6922898/cant-get-a-notification-when-connecting-an-external-accessory-to-the-3-5-mm-hea – Sbhklr Apr 18 '12 at 15:51
  • Thanks the link is useful, however I was more in interested in how people get around the lack of broadcasts from the system, I included my complete problem to give a bit of context but subsequently ended up making my post seem like a different question – rogermushroom Apr 18 '12 at 15:57
  • 2
    Well there are a few system events you can register for. For this pupose you use NSNotificationCenter. This features a broadcasting concept. See: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html – Sbhklr Apr 18 '12 at 16:23
  • Zode64 Sir ... did u find the solution to receive broadcast as android ?? if so , wats it equivalent .. ?? help... – Subbu Jan 23 '13 at 07:44
  • @CodeJack - I am afraid not. If you have checked out local and push notifications (as referred to in the question) and want your app to be available on the app store and not only jail broken phones then you are out of luck. I also understand the decision not to include a n API like this is woven in with apple's philosophy of user experience and control and so there isn't likely to be a solution for a while. – rogermushroom Jan 23 '13 at 17:39

1 Answers1

3

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.

rogermushroom
  • 5,486
  • 4
  • 42
  • 68