Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)")
        })
like image 713
A. Buksha Avatar asked Oct 19 '17 07:10

A. Buksha


People also ask

How do I turn off OneSignal push notifications?

To unsubscribe from Chrome on Android when you receive a notification: Tap the notification when it is in your notification tray.

How do I use OneSignal push notifications on Android?

Send Your First Push NotificationNavigate to the OneSignal dashboard. Select Check Subscribed Users. If everything went well, you should see a green pop-up message indicating that the connection was successful. You can proceed to create your first notification by clicking on the blue Send a Message button.


1 Answers

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.

like image 184
Ali Varli Avatar answered Sep 24 '22 02:09

Ali Varli