5

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)")
        })
A. Buksha
  • 830
  • 9
  • 14

3 Answers3

6

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.

Mr.Kushwaha
  • 491
  • 5
  • 14
Ali Varli
  • 189
  • 1
  • 6
5

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

Hanry
  • 51
  • 1
  • 3
0

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;
}
NickCoder
  • 1,504
  • 2
  • 23
  • 35