当应用程序处于焦点状态时,无法将 OneSignal 通知显示为横幅:iOS
Not able to display OneSignal notification as a Banner when the App is in focus :iOS
我正在使用 OneSignal 向设备发送通知,因为 iOS.I 能够向特定设备发送通知,但如果用户在应用内,它会将通知显示为警报.我想把它作为横幅展示。我在 "One signal regarding OSNotificationDisplayType" 上找到了一些文档,但我不知道如何使用它。
OneSignal.postNotification(["contents": ["en": "Test Message"], "include_player_ids": [oneSignalId]])
我需要有关在应用程序处于焦点时将通知显示为横幅的帮助
您的应用程序打开时不会显示通知。通知横幅只会在您的应用处于后台或关闭时显示。
您需要创建一些自定义横幅,以便在您的应用程序打开时向用户显示通知。
您可以通过以下方式设置通知横幅
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])
我正在使用 OneSignal 向设备发送通知,因为 iOS.I 能够向特定设备发送通知,但如果用户在应用内,它会将通知显示为警报.我想把它作为横幅展示。我在 "One signal regarding OSNotificationDisplayType" 上找到了一些文档,但我不知道如何使用它。
OneSignal.postNotification(["contents": ["en": "Test Message"], "include_player_ids": [oneSignalId]])
我需要有关在应用程序处于焦点时将通知显示为横幅的帮助
您的应用程序打开时不会显示通知。通知横幅只会在您的应用处于后台或关闭时显示。
您需要创建一些自定义横幅,以便在您的应用程序打开时向用户显示通知。
您可以通过以下方式设置通知横幅
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])