didReceiveRemoteNotification Delegate method calling when i open the app from terminate state,but its not calling when the application in background or foreground...
didReceiveRemoteNotification Delegate not called
1) it's not clear to me what you mean when you write "didReceiveRemoteNotification Delegate method". Perhaps you mean "didReceiveRemoteNotification method in the application's delegate ....."
2) this method is deprecated and it only is intended to work in the foreground.
3) Use this method:
didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
It works in foreground and background as you want.
You may also need to do somethng like this:
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
//this does not seem to be necessary!!!! but now I removed the earlier entry for this. It used to trigger each time above
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}];
Yes we are using the above code for remote notifications, but once I kill the app and tap on the notification then didReceiveRemoteNotification works as expected
//Its working as expected as well as didReceiveRemoteNotification called..
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[self application:application didReceiveRemoteNotification:remoteNotifiInfo fetchCompletionHandler:^(UIBackgroundFetchResult fetch){
}];
}
But when the app is in Background or Foreground didReceiveRemoteNotification method not called...All Xcode Remote notification setups are configured correctly. But still delegates not called..
>.....once I kill the app and tap on the notification then didReceiveRemoteNotification works as expected
didReceiveRemoteNotification has been deprecated. You can no longer have any expectations as to how it will or will not work. Stop using it.
Are you also reporting that
didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
is not getting called?????