Will iOS wake up my application when I receive silent push notifications? (When the application does not work)

Update question:

Requirement: as soon as I receive a quiet notification, I want to start the web service and show one liner in the notification panel. It should work if the application is also killed. any workaround?

I am trying to use the following method.

I am new to iOS, and I struggled with a silent notification of interpretation, searched a lot and got stuck. Will iOS wake up my application when I receive a quiet push notification when the application does not start (for example, when the application is removed from the application switcher).

my payload is

{ 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 the application is in the foreground, and background.cant wakes up my application when the application does not work (the application does not start or does not start from the application switcher).

+6
source share
5 answers

If the application was removed from the App Switcher, iOS will not wake your application, as the user specifically asked to close your application.

If a user opens the application at least once and does not delete it from the App Switcher, iOS will wake your application.

What we did with the server to deal with this: If the user application does not connect a minute after we sent a notification without sound (you can set it as you wish), we send another silent push notification to alert the user. Since an application (not closed by the user) should automatically retrieve data, it should take less than a minute.

But for this, of course, you need a more complex server code than just transmitting silent clicks.

EDIT: (Receiving a vote on this item showed me that it is out of date)

This answer is no longer Truth ... now you can PushKit to wake the application to do some minor things (like downloading small pieces of data to update content), even if the application has been removed from the App Switcher.

+7
source

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

Use this method to handle incoming remote notifications for your application. Unlike the application:didReceiveRemoteNotification: method, which is called only when your application is running in the foreground, the system calls this method when your application is running in the foreground or background. In addition, if you enable remote notifications in the background, the system launches your application (or wakes it from a paused state) and puts it in the background when a remote notification arrives. However, the system does not automatically start your application; if the user has the power, stop it. In this situation, the user must restart the application or restart the device before the system again tries to start the application automatically.

This clearly suggests that with the new “Background Printing” feature, you can only wake up an application if your application is paused. If it was not forcibly terminated by the user .

+2
source

Follow the instructions below.

  • Listen to silence when the application is killed.

  • When clicked (in didReceiveRemoteNotification), go to the webservice call

  • When you receive data from webservice, send LOCAL PUSH (with the text that you receive from webservice)

Hope this is what you wanted.

Please let me know if you need anything else.

0
source

As far as I tested, when the application ends with the user (switching using the application switcher), you will not have background runtime due to the silence of the push (content-available) flag or background fetch.

Also this:

Also keep in mind that if you kill your application using the application switcher (i.e. scrolling to kill the application), then the OS will never restart the application regardless of the push notification or background fetch. In this case, the user must manually restart the application once, and then from this indicate the direction of the background actions. -pmarcos (Apple employee)

From the apple forums: https://devforums.apple.com/message/873265#873265

0
source

You can get a PUSH notification and work with it. I know a little to do this ... Open AppDelegate.m and find or put this method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions . After that, put code like my in this method:

 NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo) { NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; NSString *alertType = [apsInfo objectForKey:@"type"]; //my own param in PUSH-notification globalPushType = alertType; //global variable for working with it in some ViewControllers after app load } 

I know this helps a lot of people. =)

-3
source

All Articles