当应用程序处于焦点时,无法将OneSignal通知显示为横幅:iOS

时间:2016-11-19 18:58:25

标签: ios swift xcode8 ios10 onesignal

我正在使用OneSignal将设备发送到iOS设备通知。我可以向特定设备发送通知,但如果用户在应用内,它会将通知显示为提醒。我想要将它显示为横幅。我找到了一些关于“关于OSNotificationDisplayType的信号”的文档,但我无法弄清楚如何使用它。

OneSignal.postNotification(["contents": ["en": "Test Message"], "include_player_ids": [oneSignalId]])

当应用处于焦点时,我需要有关将通知显示为横幅的帮助

2 个答案:

答案 0 :(得分:0)

只要您的应用程序处于打开状态,通知就不会显示。通知横幅广告只会在您的应用处于后台或已关闭时显示。

您需要创建一些自定义横幅,以便在打开应用时向用户显示通知。

答案 1 :(得分:0)

您可以按以下方式设置通知横幅

kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.notification.rawValue

您必须在OneSignal中使用它。initWithLaunchOptions - 方法

https://documentation.onesignal.com/docs/ios-native-sdk#section--initwithlaunchoptions-

OneSignal.initWithLaunchOptions(launchOptions, appId: "your app id", handleNotificationReceived: { (notification) in
            print("Received Notification - \((notification?.payload.notificationID)!)")
        }, handleNotificationAction: { (result) in
            let payload: OSNotificationPayload? = result?.notification.payload

   var fullMessage: String? = payload?.body
            if payload?.additionalData != nil {
                var additionalData: [AnyHashable: Any]? = payload?.additionalData
                if additionalData!["actionSelected"] != nil {
                    fullMessage = fullMessage! + "\nPressed ButtonId:\(additionalData!["actionSelected"])"
                }
            }

            print(fullMessage!)
        }, settings: [kOSSettingsKeyAutoPrompt : true,
                      kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.notification.rawValue])