Is there a way to persist an iOS app in the background such that it starts up automatically when the device is turned on and will re-launch later if terminated? I have read a few posts on either voip and gps services. My app sends emergency SMS messages with the user's location. It needs to remain active to listen for distress triggers. Would it be possibly to start up the app automatically with sending push notifications to the app using an APNS server?
Asked
Active
Viewed 5,606 times
0
-
You can use the location background mode - it sounds like your app has a valid reason to use that mode. – Paulw11 Jun 16 '15 at 12:12
1 Answers
2
Yes, you can start your app using APNS.
1) You have to set "content-available" to 1 in the notification body.
2) You have to implement:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
3) And have the right background modes: Background Modes
But be careful, your users can turn this off by disabling Background App Refresh in the iPhone Settings. You can check this in code:
[UIApplication sharedApplication].backgroundRefreshStatus!=UIBackgroundRefreshStatusAvailable

Nils Ziehn
- 4,118
- 6
- 26
- 40
-
Any recommendations easy ways to setup APNS? Any services that manage this? – Jack Shultz Jun 17 '15 at 00:52
-
There are many, you can use parse.com or amazon aws. Parse is easier setup I guess, but amazon can do a lot more – Nils Ziehn Jun 17 '15 at 10:27
-
Thanks I just started playing with a heroku add-on called zeropush. I'll see if I can achieve with that. – Jack Shultz Jun 18 '15 at 01:23
-
I got the push notification sending but it does not activate the app. I implemented your objective-c code in my app delegate. – Jack Shultz Jun 22 '15 at 16:46
-
-
This is my notification notification = { "alert": "", "content_available": true }; – Jack Shultz Jun 22 '15 at 16:51
-
It's not an underscore, its a "-" character content-available, also you should use a 1 instead of true – Nils Ziehn Jun 22 '15 at 16:52
-
It looks like the push notification library I'm using does not accept that format. I'm using this NPM https://www.npmjs.com/package/nzero-push – Jack Shultz Jun 22 '15 at 16:54
-
Well, I don't know that library, I just know that apple requires it to be "content-available", have you ever tried calling the notify method with that? zeroPush.notify(platform, deviceTokens, {"alert":"asd","content-available":1}, function()....); – Nils Ziehn Jun 22 '15 at 17:03
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/81205/discussion-between-jack-shultz-and-nils-ziehn). – Jack Shultz Jun 22 '15 at 17:11
-
I switched to https://www.npmjs.com/package/request I have more control over the request body and headers now. I put the updated code in the chat. I can now use "content-avaialable": 1 but it does not launch the app – Jack Shultz Jun 22 '15 at 19:39
-
You have misspelled content-available. I have this working in a simple case. The app is launched in the background. You won't see it in the list of tasks at the bottom of the screen. You can't make the app switch to the front. – Alex Zavatone Jan 29 '16 at 17:59