ios 10当应用程序位于前台时,即使使用UNNotificationPresentationOptionAlert,也不会显示通知警报

ios 10当应用程序位于前台时,即使使用UNNotificationPresentationOptionAlert,也不会显示通知警报,ios,objective-c,push-notification,apple-push-notifications,ios10,Ios,Objective C,Push Notification,Apple Push Notifications,Ios10,在ios 10+中的AppDelegate.h文件中,我导入UserNotifications并设置UNUserNotificationCenterDelegate,如下所示: #import <UIKit/UIKit.h> #import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotifi

在ios 10+中的AppDelegate.h文件中,我导入UserNotifications并设置UNUserNotificationCenterDelegate,如下所示:

#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>

但当应用程序在前台运行时,不会显示任何警报:(我错过了什么?

苹果说:如果你的应用程序在前台运行时收到本地或远程通知,你有责任以特定于应用程序的方式将信息传递给用户。 当应用程序位于前台时,将调用通知委托。您需要在中实现警报

application:didReceiveRemoteNotification:fetchCompletionHandler: delegate

这是有道理的:因为如果应用程序在前台,它就在用户面前,因此没有必要向通知中心发出通知。我看到许多开发人员试图声称这是一个“bug”当这是iOS10+中的新行为,并且他们无法理解更改时否,不再是在iOS10中,您现在可以决定在应用程序位于前台时向最终用户显示警报(:iOS10:即使应用程序位于前台,也会显示通知)-阅读应用程序位于前台时获取通知部分是的,我在考虑使用旧的通知时-它们不会出现
application:didReceiveRemoteNotification:fetchCompletionHandler: delegate