Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Alert when App is on Foreground with Incoming OneSignal Push Notification?

When my app is in the foreground, there is a alert that appears. How do I prevent this from appearing when receiving push notifications?

like image 781
Tim Nuwin Avatar asked Oct 20 '16 23:10

Tim Nuwin


2 Answers

In your didFinishLaunchingWithOptions method of AppDelegate you have to add kOSSettingsKeyInAppAlerts = NO

[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil
                            settings:@{kOSSettingsKeyInAppAlerts:@NO}];
like image 89
Bhavin Ramani Avatar answered Sep 23 '22 04:09

Bhavin Ramani


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])
like image 32
emresancaktar Avatar answered Sep 25 '22 04:09

emresancaktar