当OneSignal推送通知到来时,如何防止应用程序在前台时出现警报?

7

当我的应用程序在前台运行时,会出现一个提示。我该如何防止在接收推送通知时出现此提示?

4个回答

8
AppDelegatedidFinishLaunchingWithOptions方法中,您需要添加kOSSettingsKeyInAppAlerts = NO
[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil
                            settings:@{kOSSettingsKeyInAppAlerts:@NO}];

3
请注意,kOSSettingsKeyInAppAlerts已经不再使用,应改用kOSSettingsKeyInFocusDisplayOption - jkasten

6

针对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])

3

默认情况下,当应用程序处于焦点状态时,OneSignal会将通知显示为警报对话框。要更改此设置,请在initWithLaunchOptions中传递kOSSettingsKeyInFocusDisplayOption,并将其值设置为OSNotificationDisplayTypeNotificationOSNotificationDisplayTypeNone


1
我是这样做到的。在你的AppDelegate didFinishLaunchingWithOptions中添加以下代码。
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none

在最后一行中的 </p>。
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
}

这是 OneSignal文档

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接