问题
I've created a React-native app (tested in android) using WebView with the initial URL of my company's website. I want the user to be able to get redirected to a spesific website's product page (for example https://www.test.com/product/hoodie-with-zipper/) WHEN they clicked the OneSignal push notification with the intended launch URL included in the sent notification. The problem is, I want the user to open the URL with my WebView App, not the browsers.
The features I've implemented and tested so far:
Implemented and Tested WebView (no problems so far)
Implemented and Tested deeplink locally (with android scheme of 'myapp://', no problems so far)
Implemented OneSignal push notification SDK for react-native and its firebase requirements (no problems so far)
As I've mentioned in the point 2 before, I've tried and successfully implemented the deeplink with the android scheme of 'myapp://'. But, when I tried to implement the android scheme of 'https://', the launch URL from OneSignal push notification got opened with browser instead, not my WebView app.
I want the user to be able to get redirected to a spesific website's product page (for example https://www.test.com/product/hoodie-with-zipper/) WHEN they clicked the OneSignal push notification with the intended launch URL included in the sent notification, but it'll be opened with React-native WebView instead of browser.
^ So, what should I do to achieve that? Thanks in advances.
回答1:
You should handle this yourself by passing in the URL via additional data in the notification. Then, in your app you should open a webview to the specified url.The Launch URL feature on the dashboard or the url field on the REST API automatically opens the web browser on the mobile device when the notification is tapped on. If you would like to open the URL inside your app instead of the browser, you need to send your notification with custom data that can read by your app's SDK. If you're using our dashboard to send notifications, the sending notification options allows you to include additional data to be sent with your notification. If you're using our API to send notifications, you can set the 'data' field to a JSON object hash of extra custom data. For example, you could set targetUrl
for the key and https://google.com as the value. Then in your app's code read the targetUrl value from additionalData in the NotificationOpened callback (name depends on the OneSignal SDK used).
来源:https://stackoverflow.com/questions/57492989/how-do-i-open-https-url-from-one-signal-push-notification-within-my-webview-reac