问题详述
iOS 在前台可以弹出通知吗?
问题解答
- iOS 10 +,前台通知触发回调处理完成后,调用
completionHandler可实现前台通知弹出,具体参考:
/*** App 处于前台时收到通知 (iOS 10 + )* 只有当应用程序位于前台时,该方法才会在委托上调用。如果方法未被执行或处理程序没有及时调用,则通知将不会被提交。* 应用程序可以选择将通知呈现为 声音、徽章、警报、或通知列表中。此决定应基于通知中的信息是否对用户可见。*/- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {// 处理完成后调用 completionHandler ,用于指示在前台显示通知的形式// completionHandler() 功能:可设置是否在应用内弹出通知// 在 iOS 10 + 中 通知在前台的显示设置:// 1、通知在前台不显示// 如果调用下面代码: 通知不在前台弹出也不在通知栏显示// completionHandler(UNNotificationPresentationOptionNone);// 2、通知在前台显示// 如果调用下面代码: 通知在前台弹出也在通知栏显示// completionHandler(UNNotificationPresentationOptionAlert);// 3、通知在前台显示 并带有声音// 如果调用下面代码:通知弹出,且带有声音、内容和角标completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);}
- < iOS 10,通知不支持前台弹出 , 需自行处理 。
该文章对您有帮助吗?