question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webview does not deeplink to open Custom URL Scheme on iOS

See original GitHub issue

Bug description: On iOS, the following code does not redirect to open Custom URL Scheme. However, if I change the Custom URL MyApp:// to https://, it can open the link just fine.

<WebView
  source={{ html:
    `
    <html>
      <body>
        <script type='text/javascript'>
          window.location.href='MyApp://'
        </script>
      </body>
    </html>
    `
  }}
/>

Expected behavior: WebView can open Custom URL (or open MyApp in other word)

Environment:

  • OS: iOS
  • OS version: 14.5.1
  • react-native version: 0.62.2
  • react-native-webview version: 11.2.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

3reactions
focalsolutioncommented, May 23, 2021

I later find out that we need to specify the Custom URL in Info.plist for the key LSApplicationQueriesSchemes in order to make this works on iOS.

Just want to share here in case it might be useful for others.

1reaction
fabriciosautnercommented, Jan 29, 2022

same problem

My info.plist:

      <plist version="1.0">
         <dict>
             .....
             <key>LSApplicationQueriesSchemes</key>
             <array>
                  <string>com.xxxxxxx://garmin/success</string>
             </array>
            .......
         </dict>
      </plist>

EDIT

I got around this problem as follows:

In my backend, instead of redirecting to ‘com.myapp://route/success’, I redirect to any HTTP route, for example: ‘https://www.myapp.com/route/success’.

So the onShouldStartLoadWithRequest function can intercept and do what I need to do.

Currently Deep Link does not work, as the onShouldStartLoadWithRequest function does not receive the URL.

Code snippet on the backend:

 ....  response.redirect(`${process.env.WEB_URL}/route/success`);

Code snippet in the App:

onShouldStartLoadWithRequest = (request) => {
     const success = request.url.includes('/route/success');
     if (success) {
           ...actions
     }
    return true;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ios - WKWebView not opening custom URL scheme (js ...
This solution will work without adding custom URL Schemes to your apps plist file via LSApplicationQueriesSchemes . (Which is necessary since iOS 10...
Read more >
Custom URL schemes in a WKWebView
This article is about handling custom URL schemes inside a WKWebView, and I'll give you a couple of examples that allow you to...
Read more >
Deep Linking Using Custom URL Scheme Example in Swift
Source code is at: http://swiftdeveloperblog.com/deep-linking-using- custom - url - scheme /
Read more >
iOS Custom URI Handlers / Deeplinks / Custom Schemes
Go to the URL Handlers section. In URL schemes, click Refresh, and on the left you'll find a list of all custom schemes...
Read more >
Allowing apps and websites to link to your content
If the user has not installed your app, the system opens the URL in Safari, allowing your website to ... open(_:options:completionHandler:) in iOS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found