Is there a way to wakeup suspended app in iOS without user or server intervention

Haris Farooqui picture Haris Farooqui · Feb 14, 2016 · Viewed 23.4k times · Source

Is there way to wakeup iOS app without using "The significant-change location service"?

I need to wakeup my app without server or user intervention Some thing similar to Alarm clock wherein you get an alert popup when it's time to wakeup.

UILocalNotification - Won't work since it would need user and sever intervention.

Silent Push Notifications - Won't work since you cannot send local notifications as Silent push notifications. These can only be sent by Server. Which means it would need Server intervention.

Background Fetch - Won't work since there is not guaranteed trigger time.

Am I missing something?

Answer

Jessedc picture Jessedc · Feb 14, 2016

Edit: You have adjusted your question to explicitly state 'without user or server intervention'.

No, As far as I'm aware by design iOS does not provide an explicit way to wake up your app at determinate time in the future. You can continue long running tasks while in the background, opportunistically fetch updated content, remind users to re-open your app if need be and prompt the first two with silent push notifications if need be.

Here are some hints on the three options above:

UILocalNotification

The easiest way is to schedule some UILocalNotifications at a time in the future but in order to wake up your app you need to interact with the notification. This may not be what you want.

Silent Push Notifications

Another option since iOS 7 is a content-available or silent push notification. You setup a particular payload for this kind of notification and if your app has the correct UIBackgroundMode value setup it will be delivered to your app silently:

The payload would look something like this:

{
    "aps" : {
        "content-available" : 1
    },
    "content-id" : 42
}

And you would receive it in your app delegate with a specific delegate method:

- (void)         application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo 
      fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"Remote Notification userInfo is %@", userInfo);

    NSNumber *contentID = userInfo[@"content-id"];
    // Do something with the content ID
    completionHandler(UIBackgroundFetchResultNewData);
}

You can then use this opportunity download content or update your app quickly if need be, take a look at the UIBackgroundModes and background execution documentation for more info on this approach.

The Multi-Tasking article at Objc.io is also a good start for this approach.

Background Fetch

If you read into the background modes documentation from Apple it's possible using the UIBackgroudnModes value fetch for your app to be woken up opportunistically and given time to download or update it's data.

Apple's documentation on this mentions it's use case:

Apps that need to check for new content periodically can ask the system to wake them up so that they can initiate a fetch operation for that content. To support this mode, enable the Background fetch option from the Background modes section of the Capabilities tab in your Xcode project.