Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Apple's silent push notifications launch my app in the background?

According to Apple's documentation I can register for silent notification by adding "content-available" = 1 key-value in aps payload dictionary. I want my app to wake up in background when a silent notification arrives. I set App downloads content in response to push notifications value to Required background modes in my info.plist

This is my payload dictionary

{"aps":
      {
       "alert":"Notification alert","badge":1,"sound":"default","content-available":1
      }
}

I am getting callbacks in -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler while my app is in background. But my question is can we get callback to this or any other method when our application is in killed state?

I don't want my app user to see the notification but I want my app to perform certain task by waking it up in background through silent notifications.

Any suggestions would be appreciated.

like image 590
Vijay Sanghavi Avatar asked Dec 15 '15 13:12

Vijay Sanghavi


1 Answers

When the device receives a push message with content-available set, your app gets launched in the background by Apple. Users won't be aware of it. From the docs:

content-available: Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, -application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

Also from docs

didReceiveRemoteNotification: 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.

like image 159
TwoStraws Avatar answered Oct 06 '22 04:10

TwoStraws