When receiving push notification in iOS and app in the background the didReceiveRemoteNotification method is not called


#1

We are using CleverTap for push notification and we have to store all received push in to the local storage of app. When push receive and app is in the background the didReceiveRemoteNotification method is not called but same method is called for the worklight push notification


#2

Hi. didReceiveRemoteNotification is not called by the system when your app is in the background. This is an OS limitation not a CleverTap one.

From the Apple Developer docs:
optional func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
Implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method instead of this one whenever possible. If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.
If the app is running, the app calls this method to process incoming remote notifications.

you could try application:didReceiveRemoteNotification:fetchCompletionHandler:, which is callable in the background, for your use case. To do that, enable remote notifications background mode for your app and send the content-available flag in your push.

from the Apple Developer docs:
optional func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. 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.

Also, starting in iOS10, you could also use a Notification Service extension, which will be called while your app is in the foreground, background or force quit, to intercept the payload and then write it to an app group shared user defaults so your main app can access it.


#3

After xcode 8.3 with ios 10.3 update this method is not called for push notification received tap in iPhones. Please update us.

didReceiveRemoteNotification userInfo: [NSObject : AnyObject])


#4

Hey @bharath.viswa1,

The signature of the method has been updated by Apple.
Can you please check : https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application

Please do let me know how it goes.


#5

@harsh I already have this delegate in the appdelegate, but the notification tap is not firing this method when it was received. Please let me know if the issue exists.


#6

Anone who upgraded to xcode 8.3, ios 10.3 have this issue?


#7

UNUserNotificationCenterDelegate userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is invoked instead on iOS10. UNUserNotificationCenterDelegate is implemented internally in Pushwoosh.framework and is set using

[UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
If you want to have full control over system callbacks you can use your own UNUserNotificationCenterDelegate, but do not forget to propagate both callbacks 1, 2 to [PushNotificationManager pushManager].notificationCenterDelegate.