Application: didReceiveLocalNotification never called ios 8

Is there a known issue with:

application:didReceiveLocalNotification delegate 

on iOS 8?

My application creates local notifications using UILocalNotification . When the application is in the background, I get notifications, and when I click on the notification banner, it goes to my application. But this method:

 -(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 

never called in iOS 8 (Xcode 5.1.1), but works well on iOS 7 or earlier.

PS I also tested the project from this site: http://www.appcoda.com/ios-programming-local-notification-tutorial/ and it does not work on iOS 8.

+5
source share
4 answers

Use it for iOS8

 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler{ } 
+5
source

In fact, the solution on iOS 8 should request authorization for the notification options for the user, otherwise the delegate method -didReceiveLocalNotification: will never be called. You can do this by adding this code to the -didFinishLaunchingWithOptions :: method

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; } 

This will show the user a warning requesting permission to display notifications. If it accepts, the delegate method will be called whenever a local notification is issued.

+7
source

I am facing the same problem ...

You must modify to use the following code:

 // register notification for push mechanism if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; } 

instead of the original:

 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 
+4
source

I noticed the same thing on iOS8Beta5. The same code works fine on iOS8Beta4.

Edit: If, as the answer suggests, we need to handle it differently - then why did they refuse support between the two beta versions. It would be wise if iOS8Beta1 build behaved like this. That is why I feel this is a mistake.

+1
source

Source: https://habr.com/ru/post/1200025/


All Articles