I had disable infocus, autoprompt, launch url and app alert in onesignal launch options, but still banner is displayed when app is in foreground, is am a missing something or i had written something extra, here is my code, please review below code and help me out.
//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)")
})
You should change your onesignalInitSettings to just be:
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false, kOSSettingsKeyInAppLaunchURL: false]Check out the github example in Swift: https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples/SwiftExample
Also, calling:
OneSignal.promptForPushNotifications(userResponse: { accepted in print("User accepted notifications: \(accepted)") })in the AppDelegate like this will prompt the user when they first open the app in the same way as setting
kOSSettingsKeyAutoPrompt: truein the onesignalInitSettings.In case you were trying to prompt users at a later time in the app.