首页 > 解决方案 > 避免在应用程序处于前台时显示通知警报

问题描述

嗨,我使用此 UNUserNotificationCenterDelegate 来避免应用程序在前台使用此功能时发出警报通知

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler  API_AVAILABLE(ios(10.0)){
    completionHandler(UNNotificationPresentationOptionAlert);
}

但我收到通知选项警报和横幅如何在应用程序处于前台时删除警报?

标签: iosobjective-cunusernotificationcenter

解决方案


您必须在 willPresent 方法中应用条件,以检查应用程序的状态,如果 State 是 UIApplecationStateForeGround 则什么都不做,否则它们遵循 UNNotificationPresentationOptionAlert 。


推荐阅读