[英]ios 10 when app is in foreground no notification alert is show even with UNNotificationPresentationOptionAlert
在ios 10+中,在AppDelegate.h文件中,我導入UserNotifications並設置UNUserNotificationCenterDelegate,如下所示:
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
然后在AppDelegate.m文件中,添加[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
在我的didFinishLaunchingWithOptions
方法中。
然后,如下添加userNotificationCenterhandler。
- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert);
}
但是當應用程序處於前台狀態時,不會顯示警報:(我想念什么?
蘋果公司說: 如果您的應用程序在前台運行時收到本地或遠程通知,則您有責任以特定於應用程序的方式將信息傳遞給用戶。 當應用程序在前台notification delegate
調用notification delegate
。 您需要實施警報
application:didReceiveRemoteNotification:fetchCompletionHandler: delegate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.