DidReceiveLocalNotification does not receive a call after using UNUserNotificationCenter

I am planning local notifications. It works in iOS 9.x, but since iOS 10

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

not called when the app is running on iOS 10.

I know that iOS introduced a new infrastructure UserNotifications, but should not stop working with the iOS 9 APIs.

How can I solve this problem?

+4
source share
1 answer

, iOS 10 UNUserNotifications , . , , .

[UNUserNotificationCenter currentNotificationCenter].delegate = yourDelegate;

...

// In your delegate ...

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {

    // Notification arrived while the app was in foreground

    completionHandler(UNNotificationPresentationOptionAlert);
    // This argument will make the notification appear in foreground
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)())completionHandler {

    // Notification was tapped.

    completionHandler();
}

, () application:didReceiveLocalNotification application:didReceiveRemoteNotification:fetchCompletionHandler, : UNUserNotificationCenter.

, (, content-available, alert, sound badge), application:didReceiveRemoteNotification:fetchCompletionHandler, .

+4

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


All Articles