Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application:didReceiveLocalNotification never called on ios 8

Is there any known problem issue with:

application:didReceiveLocalNotification delegate

on iOS 8?

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

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

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

P.S. I've also tested project from this site: http://www.appcoda.com/ios-programming-local-notification-tutorial/ and it doesn't work on iOS 8.

like image 953
edzio27 Avatar asked Aug 11 '14 13:08

edzio27


Video Answer


2 Answers

Actually, the solution on iOS 8 is to request authorization for notifications settings to the user, otherwise the delegate method -didReceiveLocalNotification: will never be called. You can do so 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 an alert view asking for permission to display notifications. If she accepts, the delegate method will be called whenever a local notification is fired.

like image 80
zmit Avatar answered Oct 01 '22 18:10

zmit


Use this for iOS8

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

}
like image 32
Rajneesh071 Avatar answered Oct 01 '22 18:10

Rajneesh071