简体   繁体   中英

Push Notification Method called when app is killed

I removed the app from background recent apps, sent notification then my device gets fcm notification succesfully , but I would like to know which method is called when notification is received.Because on receiving notification in my app it has to print receipt automatically. How this can be done?This method is not called in this case.

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

Plz suggest which method receives the notification payload when app is removed from background(recent apps)

There is no way to receive remote notification handlers for notifications if the app has been force-quit.

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

https://developer.apple.com/forums/thread/65817

https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application

You can use UINotificationExtension to execute code on Remote Notification even if app is terminated

To share data between Extension and App, you can use Keychain Shared Content

I have encountered the same issue when i was working with Firebase notification in android. its happening because of the payload of notification. check the Zohaib Ali answer.It will solve your problem

notification should be send using Firebase Rest API in order to receive notification in background

If i understood your concern is which method will call when App is killed and a notification receives. By default, no method will call but by modifying APNS Payload you can invoke the application at the time of notification.

For this, you have to enable Background refresh from Capabilities. Also, In your push payload, you have to add one key

"content-available" : 1

This will invoke your application though your application is killed. You have approx 30 seconds to perform any task.

At that moment, below method will be called. And invoking does not mean your application can print logs in debug area. To check You have to do some logic like saving data in UserDefaults or can update server regarding this.

application:didReceiveRemoteNotification:fetchCompletionHandler:

You can find more info https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app

https://medium.com/@m.imadali10/ios-silent-push-notifications-84009d57794c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM