Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will iOS awake my app when i receive silent push notification?(When app is not in running state)

Update Question :

The requirement is; as soon as I receive silent notification, I want to run a web service and show the one liner in the notification bar. It has to work if the app is killed also. any workaround ?

I am trying following method below.

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).

my pay load is as

{ 
      aps: {
              content-available: 1,
              sound: ""
     }
}

.

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{

int CA=[[[userInfo valueForKey:@"aps"] valueForKey:@"content-available"] intValue];

if (CA==1) {

    my action...

}

 completionHandler(UIBackgroundFetchResultNewData);
}

this method is called and works fine when app is in foreground and background.cant awake my app when app is not in running state(i.e app is not launched or killed from app switcher)..

like image 576
Guruanu_Deepu Avatar asked Apr 08 '14 12:04

Guruanu_Deepu


2 Answers

If the App has been removed from the App Switcher, iOS will not awake your app, since the user specifically asked for closing your app.

If the user open your app at least once, and do not remove it from App Switcher, iOS will awake your app

What we have done server-side to handle this is : If the user's app doesn't connect in the minute after we sent the silent notification, (you can set it as you wish), we send another non-silent push notification to alert the user. Since the App (is not closed by the user) should automatically fetch data, it should take under a minute.

But for that of course you need a more complex server code than simply sending silent push.

EDIT : (Getting a vote up on this question showed me that it was outdated)

This answer is no longer True... you can now with PushKit wake up your app to do some minor things (like downloading small chunks of data to update content) even if the App has been removed from App Switcher.

like image 87
TheSquad Avatar answered Oct 23 '22 05:10

TheSquad


Please checkout this:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

This clearly says that Using new Background Push feature you can Awake the App Only if Your app is suspended Not if it is terminated forcefully by User.

like image 32
Mrug Avatar answered Oct 23 '22 06:10

Mrug