避免在应用程序处于前台时显示通知警报
avoid showing alert for notification while app is in foreground
嗨,我使用这个 UNUserNotificationCenterDelegate 来避免应用程序在前台使用此功能时的警报通知
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
completionHandler(UNNotificationPresentationOptionAlert);
}
但我收到的通知同时包含警报和横幅选项
如何在应用程序处于前台时删除警报?
您必须在 willPresent 方法中应用条件,以检查 App 的状态,如果 State 是 UIApplecationStateForeGround 则什么都不做,否则它们将遵循 UNNotificationPresentationOptionAlert。
我发现了如何修复一个信号初始化的选项以避免显示警报
[OneSignal initWithLaunchOptions:launchOptions appId:@"YOURE_KEY" handleNotificationReceived:nil handleNotificationAction:nil
settings:@{kOSSettingsKeyInAppAlerts:@NO}];
要显示为横幅,您必须添加此代码
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
completionHandler(UNNotificationPresentationOptionAlert);
}
嗨,我使用这个 UNUserNotificationCenterDelegate 来避免应用程序在前台使用此功能时的警报通知
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
completionHandler(UNNotificationPresentationOptionAlert);
}
但我收到的通知同时包含警报和横幅选项 如何在应用程序处于前台时删除警报?
您必须在 willPresent 方法中应用条件,以检查 App 的状态,如果 State 是 UIApplecationStateForeGround 则什么都不做,否则它们将遵循 UNNotificationPresentationOptionAlert。
我发现了如何修复一个信号初始化的选项以避免显示警报
[OneSignal initWithLaunchOptions:launchOptions appId:@"YOURE_KEY" handleNotificationReceived:nil handleNotificationAction:nil
settings:@{kOSSettingsKeyInAppAlerts:@NO}];
要显示为横幅,您必须添加此代码
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
completionHandler(UNNotificationPresentationOptionAlert);
}