Reputation: 19926
My app must be able to play alarm sound no matter what upon receiving push notification.
Is there a way to configure audio session to play sound:
I do not need to publish this app to AppStore (only for my private usage), so private API is an option.
For those who may tempt to propose UILocalNotification
: those are not suitable in my case since they must obey silent / ring switch.
Upvotes: 1
Views: 1043
Reputation: 1396
If you don't want to use UILocalNotification, there is the option described here:
http://oleb.net/blog/2014/02/alarm-clock-apps-ios/
In brief, if you opt-out of iOS's multi-tasking, and you lock your phone with the app running, you can continue to run custom code:
If you do not want your app to run in the background at all, you can explicitly opt out of background by adding the UIApplicationExitsOnSuspend key (with the value YES) to your app’s Info.plist file. When an app opts out, it cycles between the not-running, inactive, and active states and never enters the background or suspended states.
However, if that isn't appropriate for your use-case, you might be able to use UIBackgroundModes
with remote-notification
to wake up your app when it receives a push notification, but then you'd have to have your own server infrastructure to keep track of your alarms. Even then, I'm not sure if you could start playing a sound while your app is in the background...
Upvotes: 1