Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 570
Haris Farooqui Avatar asked Feb 14 '16 03:02

Haris Farooqui


People also ask

Will iOS awake my app when I receive silent push notification?

I am new to iOS and i struggled with silent push notification,googled a lot and got stuck. Will iOS awake my app when i receive silent push notification when app is not launched(i.e when app is removed from app switcher). this method is called and works fine when app is in foreground and background.

What is suspended state in iOS?

When the app is in the background state, the iOS will suspend all activities of this app before iOS 13.5. So there should be no more log messages. But after several switching between the foreground state and background state, iOS stops moving this app to the suspended state, so the app keeps running in the background.

How do I keep apps from running in the background in Swift?

First, go to your project's settings and choose the Capabilities tab. You need to enable the Background Modes capability, then check the box marked Background Fetch. This modifies your app's Info. plist file to add the “fetch” background mode that enables all the following functionality.

How do I send silent push notifications?

There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.


1 Answers

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.

like image 137
Jessedc Avatar answered Oct 19 '22 16:10

Jessedc