Silent Push Notification in background also triggered didFinishLaunchingWithOptions

About 2 or 3 months ago, when my app receive a Silent Push notification([aps][content-available] = 1), only func "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler" had triggered.

But now, when my app receive Silent push, my app triggered 3 func :"didFinishLaunchingWithOptions"; "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo" and "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler".

Does Apple update this logic? Are there any solution to push silent that just triggered only one func like before?

Answered by Engineer in 800220022

I am not sure why you have not noticed these other functions being called earlier, but what you are seeing is expected. Perhaps you have made changes to your project that is now causing these functions to be triggered.

didFinishLaunchingWithOptions() is a function that will be called if your app has not been running (for example if it had been terminated by the system in the background) and now is being launched again in response to the content-available notification. When an app is launched, this function will get called. If you do not want this function to be called in response to a notification, then you can disable the "Remote notifications" Background mode for your app. This will disable your apps ability to be launched in the background and therefore didFinishLaunchingWithOptions() will no longer be called in response to a notification. But if you do this, and your app is not running at the time, you will not receive a call to the other functions either. If you want to receive notification calls when your app is not running, then you must accept that this function will also be called.

application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is a function that has been deprecated and is replaced by application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler You are expected to use the latter to replace the former. Not have both of them implemented. If you do not want didFinishLaunchingWithOptions"; "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo to be called, you can simply remove the implementation of it from your project.


Argun Tekant /  DTS Engineer / Core Technologies

I am not sure why you have not noticed these other functions being called earlier, but what you are seeing is expected. Perhaps you have made changes to your project that is now causing these functions to be triggered.

didFinishLaunchingWithOptions() is a function that will be called if your app has not been running (for example if it had been terminated by the system in the background) and now is being launched again in response to the content-available notification. When an app is launched, this function will get called. If you do not want this function to be called in response to a notification, then you can disable the "Remote notifications" Background mode for your app. This will disable your apps ability to be launched in the background and therefore didFinishLaunchingWithOptions() will no longer be called in response to a notification. But if you do this, and your app is not running at the time, you will not receive a call to the other functions either. If you want to receive notification calls when your app is not running, then you must accept that this function will also be called.

application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is a function that has been deprecated and is replaced by application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler You are expected to use the latter to replace the former. Not have both of them implemented. If you do not want didFinishLaunchingWithOptions"; "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo to be called, you can simply remove the implementation of it from your project.


Argun Tekant /  DTS Engineer / Core Technologies

Silent Push Notification in background also triggered didFinishLaunchingWithOptions
 
 
Q