How to prevent a warning when the application is in the foreground with an incoming OneSignal Push notification?

When my application is in the foreground, a warning appears. How can I prevent this message from appearing when I receive push notifications?

+6
source share
4 answers

In your didFinishLaunchingWithOptions method AppDelegate you need to add kOSSettingsKeyInAppAlerts = NO

 [OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil settings:@{kOSSettingsKeyInAppAlerts:@NO}]; 
+7
source

For Swift 3.0

 // Initialize OngeSignal with Settings for Push Notifications OneSignal.initWithLaunchOptions(launchOptions, appId: Constants.OneSignalAppID, handleNotificationReceived: nil, handleNotificationAction: { (result) in // Do Something with Notification Result }, settings: [kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.none.rawValue]) 
+6
source

By default, OneSignal displays notifications in the form of alert dialogs when the application is focused. To change this pass kOSSettingsKeyInFocusDisplayOption with a value of OSNotificationDisplayTypeNotification or OSNotificationDisplayTypeNone to initWithLaunchOptions .

+3
source

I have achieved it this way. Add the following code to your AppDelegate doneFinishLaunchingWithOptions

 OneSignal.inFocusDisplayType = OSNotificationDisplayType.none 

on the last line in

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { OneSignal.inFocusDisplayType = OSNotificationDisplayType.none return true } 

we have these 3 options

 public enum OSNotificationDisplayType : UInt { /*Notification is silent, or app is in focus but InAppAlertNotifications are disabled*/ case none /*Default UIAlertView display*/ case inAppAlert /*iOS native notification display*/ case notification } 

Here's the OneSignal Documentation

0
source

Source: https://habr.com/ru/post/1011531/


All Articles