【发布时间】:2017-03-03 03:03:12
【问题描述】:
当我的应用程序在前台时,会出现一个警报。接收推送通知时如何防止出现这种情况?
【问题讨论】:
标签: ios push-notification onesignal
当我的应用程序在前台时,会出现一个警报。接收推送通知时如何防止出现这种情况?
【问题讨论】:
标签: ios push-notification onesignal
在AppDelegate 的didFinishLaunchingWithOptions 方法中,您必须添加kOSSettingsKeyInAppAlerts = NO
[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil
settings:@{kOSSettingsKeyInAppAlerts:@NO}];
【讨论】:
kOSSettingsKeyInAppAlerts 现在已被弃用,而应使用kOSSettingsKeyInFocusDisplayOption。
对于 Swift 3.0
// Initialize OngeSignal with Settings for Push Notifications
OneSignal.initWithLaunchOptions(launchOptions, appId: Constants.OneSignalAppID, handleNotificationReceived: nil, handleNotificationAction: {
(result) in
// Do Something with Notification Result
}, settings: [kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.none.rawValue])
【讨论】:
默认情况下,OneSignal 会在应用未对焦时将通知显示为警报对话框。将此通道 kOSSettingsKeyInFocusDisplayOption 的值 OSNotificationDisplayTypeNotification 或 OSNotificationDisplayTypeNone 更改为 initWithLaunchOptions 上的设置。
【讨论】:
我是这样实现的。在您的 AppDelegate didFinishLaunchingWithOptions 中添加以下代码
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
在最后一行
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
return true }
我们有这三个选项
public enum OSNotificationDisplayType : UInt {
/*Notification is silent, or app is in focus but InAppAlertNotifications are disabled*/
case none
/*Default UIAlertView display*/
case inAppAlert
/*iOS native notification display*/
case notification
}
【讨论】: