Pat*_*gar 6 ios onesignal swift3 ios10 xcode8
我在 onesignal 启动选项中禁用了聚焦、自动提示、启动 url 和应用程序警报,但是当应用程序处于前台时仍然显示横幅,是缺少某些东西还是我写了一些额外的东西,这是我的代码,请查看下面的代码和帮帮我。
//For One Signal
let notificationReceivedBlock: OSHandleNotificationReceivedBlock = { notification in
print("Received Notification: \(notification!.payload.notificationID)")
}
let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
// This block gets called when the user reacts to a notification received
let payload: OSNotificationPayload = result!.notification.payload
var fullMessage = payload.body
print("Message = \(String(describing: fullMessage))")
if payload.additionalData != nil {
if payload.title != nil {
let messageTitle = payload.title
print("Message Title = \(messageTitle!)")
}
let additionalData = payload.additionalData
if additionalData?["actionSelected"] != nil {
fullMessage = fullMessage! + "\nPressed ButtonID: \(String(describing: additionalData!["actionSelected"]))"
}
}
}
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: false,
kOSSettingsKeyInAppAlerts : false,
kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.none.rawValue] as [String : Any]
OneSignal.initWithLaunchOptions(launchOptions,
appId: oneSignalAppID,
handleNotificationReceived: notificationReceivedBlock,
handleNotificationAction: notificationOpenedBlock,
settings: onesignalInitSettings)
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
Run Code Online (Sandbox Code Playgroud)
Jon*_*onF -1
您应该将 onesignalInitSettings 更改为:
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false, kOSSettingsKeyInAppLaunchURL: false]
查看 Swift 中的 github 示例:https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples/SwiftExample
另外,调用:
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
kOSSettingsKeyAutoPrompt: true在 AppDelegate 中,这样会在用户首次打开应用程序时提示用户,方式与onesignalInitSettings 中的设置相同。
如果您稍后尝试在应用程序中提示用户。
| 归档时间: |
|
| 查看次数: |
1948 次 |
| 最近记录: |