ios - 避免在应用程序处于前台时显示通知警报
问题描述
嗨,我使用此 UNUserNotificationCenterDelegate 来避免应用程序在前台使用此功能时发出警报通知
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
completionHandler(UNNotificationPresentationOptionAlert);
}
但我收到通知选项警报和横幅如何在应用程序处于前台时删除警报?
解决方案
您必须在 willPresent 方法中应用条件,以检查应用程序的状态,如果 State 是 UIApplecationStateForeGround 则什么都不做,否则它们遵循 UNNotificationPresentationOptionAlert 。
推荐阅读
- powershell - 在 PowerShell 中重复所有行项目
- javascript - 遍历嵌套对象的dom
- javascript - 代码声明 (x - 3) 不是函数
- perl - 在逐行读取文件时保持计数
- javascript - 为数组中的每个对象赋值,无需循环
- git - 如何验证 git clone/pull 文件匹配服务器?
- metal - MetalPerformanceShaders MTLCommandBuffer 并行运行
- html - 下划线悬停效果占用整个空间,但它应该只占用文本空间
- drupal-8 - 迁移:如果实体查找未能找到匹配项,则整行都应该失败
- arrays - 检查 Excel 单元格是否包含数组项