Launch app in background automatically?

2019-06-12 21:16发布

问题:

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?

回答1:

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