Local Notification is not displayed in iOS 10

馋奶兔 提交于 2019-12-06 11:08:12
aashish tamsya

You are unable to see the local notification because your application might be in foreground. Local Notification doesn't show up if you are in foreground.

Your code is okay, but I would suggest to make some changes & test your app again.

  1. Increase trigger time to 10 seconds. UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO];
  2. Added following in applicationDidEnterBackground

[self localNotification];

  1. Make the application to go background.
  2. Wait for 10 seconds, your will get local notification.

Show Notification on Foreground

If you want to show notification when your application is in foreground then, implement

  1. Conform UNUserNotificationCenterDelegate in AppDelegate.h

  2. Add following code in AppDelegate.m

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
    }

If you're in foreground, your delegate method will be called but no visual notification will be displayed. If you really want to show a notification in foreground you can use something like:

https://github.com/pikacode/EBForeNotification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!