A. Buksha
A. Buksha

Reputation: 840

How to forbid OneSignal to open WebView when handling notification

I am trying to integrate OneSignal into my app. What I want is when user tap a notification to present desired ViewController modally. I implemented opening VC logic in handleNotificationAction while init of OneSignal. The problem is that OneSignal still opens its WebView, and I don't want it to. Is there any way to disable opening WebView when user taps notification?

let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
OneSignal.initWithLaunchOptions(launchOptions,
                                        appId: "myAppID",
                                        handleNotificationAction: { result in
                                            guard let payload = result?.notification.payload else { return }
                                            guard let additionalData = payload.additionalData else { return }
                                            guard let venueID = additionalData["internal"] as? String else { return }
                                                    DispatchQueue.main.async {
                                                        self.showVenueDetails(venueID)
                                                    }
        },
                                        settings: onesignalInitSettings)
        OneSignal.inFocusDisplayType = .notification
        OneSignal.promptForPushNotifications(userResponse: { accepted in
            print("User accepted notifications: \(accepted)")
        })

Upvotes: 6

Views: 1944

Answers (3)

Hanry
Hanry

Reputation: 51

For OneSignal SDK 3.x.x

As suggested by OneSignal, add the following key to the project's info.plist:

OneSignal_suppress_launch_urls = true

For OneSignal SDK version 2.x.x

add kOSSettingsKeyInAppLaunchURL: false to OneSignal's initSetting

Upvotes: 5

QA Appboxer
QA Appboxer

Reputation: 1

Search for initOneSignal in project. There in setting parameneter pass

kOSSettingsKeyInAppLaunchURL: @false

- (void)initOneSignal {
    [OneSignal setValue:@"react" forKey:@"mSDKType"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBeginObserving) name:@"didSetBridge" object:nil];

    [OneSignal initWithLaunchOptions:nil appId:nil handleNotificationReceived:^(OSNotification* notification) {
        [self handleRemoteNotificationReceived:[notification stringify]];
    } handleNotificationAction:^(OSNotificationOpenedResult *result) {
        if (!RCTOneSignal.sharedInstance.didStartObserving)
            coldStartOSNotificationOpenedResult = result;
        else
            [self handleRemoteNotificationOpened:[result stringify]];

    } settings:@{@"kOSSettingsKeyInOmitNoAppIdLogging" : @true, kOSSettingsKeyAutoPrompt : @false, kOSSettingsKeyInAppLaunchURL: @false}]; //default autoPrompt to false since init will be called again
    didInitialize = false;
}

Upvotes: 0

Ali Varli
Ali Varli

Reputation: 189

Yes, add kOSSettingsKeyInAppLaunchURL: false to your onesignalInitSettings. This will open URL in default browser instead of UIWebView.

If you want to display your custom view then don't use the URL parameter in the payload. Instead, use custom key-value pair in additional data.

Upvotes: 6

Related Questions