0

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)

Honey
  • 2,690
  • 11
  • 31
  • 62
  • 1
    If you terminate the app from the app switcher then no method is called when a push notification is delivered. iOS simply show the banner. – Paulw11 Aug 11 '20 at 09:55
  • @Paulw11 then how to get printed receipts automatically when push notification arrives – Honey Aug 11 '20 at 10:54
  • 2
    You can't. If the user terminates your app it doesn't run until they relaunch it – Paulw11 Aug 11 '20 at 10:55
  • However you can print the receipt when the app is launched from the notification. – La pieuvre Aug 11 '20 at 11:28
  • @Lapieuvre Yes we did this when user clicks notification, but only problem is we cant do it when app is terminated though notification is received. – Honey Aug 11 '20 at 11:29
  • Just to be sure, what's happening is that if you receive a notification and the app is in the background, when you click the notification the app opens and you can process your receipt, but if the app is kill and then you receive a notification, when you click the notification the app doesn't open? or the app opens but the didReceiveNotification is not triggered? – La pieuvre Aug 11 '20 at 11:35
  • @Lapieuvre , App opens when cliked notification in termination state and didReceiveNotification is also triggered. – Honey Aug 11 '20 at 11:42
  • So you can print receipt when the app is launched from the notification then, right? – La pieuvre Aug 11 '20 at 11:43
  • @Lapieuvre Yes. – Honey Aug 11 '20 at 11:44

4 Answers4

0

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

0

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 don't think using `UINotificationExtension` solves the problem of whether or not the app will launch/wake up if its been killed by the user. A silent background notification is the only semi-reliable way to try and get iOS to launch your app. See [Pushing Background Updates to Your App](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app) – race_carr Apr 27 '21 at 16:05
  • Hello, just test it, working. – srailov kairat May 05 '21 at 05:34
-1

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

-1

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

Bhavin Vaghela
  • 343
  • 2
  • 13
  • Everything u said is implemented , we are getting notifications perfectly ; but when app is removed from recent apps list; im not getting printing receipts automatically , because no method is called. what can be done for that – Honey Aug 11 '20 at 10:43
  • No code executes for a push notification if the user terminates the app. – Paulw11 Aug 11 '20 at 10:55