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

后端 未结 3 944
花落未央
花落未央 2020-12-09 09:16

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 simi

3条回答
  •  失恋的感觉
    2020-12-09 09:47

    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.

提交回复
热议问题