application:didReceiveLocalNotification never called on ios 8

前端 未结 4 772
耶瑟儿~
耶瑟儿~ 2020-12-17 03:32

Is there any known problem issue with:

application:didReceiveLocalNotification delegate

on iOS 8?

My application creates local noti

相关标签:
4条回答
  • 2020-12-17 04:09

    Use this for iOS8

    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler{
    
    }
    
    0 讨论(0)
  • 2020-12-17 04:13

    I meet the same problem...

    You must change 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)];
    }
    

    to instead of the original:

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    
    0 讨论(0)
  • 2020-12-17 04:16

    I have noticed the same on iOS8Beta5. Same code works fine on iOS8Beta4.

    Edit: If as the answer suggests, we need to handle it differently - then why did they drop support between two beta builds. It would make sense if iOS8Beta1 build behaved this way. This is why I feel its a bug.

    0 讨论(0)
  • 2020-12-17 04:20

    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.

    0 讨论(0)
提交回复
热议问题