我在信号启动选项中禁用了infocus,autoprompt,启动网址和应用提醒,但当应用处于前台时仍然显示横幅,是缺少的东西还是我写了一些额外的东西,这是我的代码,请查看下面的代码并帮助我。
//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)")
})
答案 0 :(得分:0)
您应该将您的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)")
})
会在用户首次打开应用时提示用户,就像在onesignalInitSettings中设置kOSSettingsKeyAutoPrompt: true
一样。
如果您以后尝试在应用中提示用户。