Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Itunes app links are not working with WkWebview

One of the webpage I load into Wkwebview has the following iTunes app link

 https://itunes.apple.com/gb/app/xx-yy-zz/id435919263?mt=8

when it's opened I'm getting the following alert

enter image description here

and here's the error that I've got.

{
    "[errorCode]" = 0;
    "[errorDescription]" = "Redirection to URL with a scheme that is not HTTP(S)";
    "[errordetail]" = "Con:myappxxxx:myorder:webview:networkerror";
    "[localizedRecoverySuggestion]" = "";
    "[url]" = "itms-appss://apps.apple.com/gb/app/xx-yy-zz/id435919263";
}

When the same iTunes link ( https://itunes.apple.com/gb/app/xx-yy-zz/id435919263?mt=8 ) is opened in UIWebview , I saw that URL gets redirected to following URL and app opens in appstore

 itms-appss://itunes.apple.com/gb/app/xx-yy-zz/id435919263?mt=8

Whereas in Wkwebview , the URL gets redirected to following URL

 itms-appss://apps.apple.com/gb/app/xx-yy-zz/id435919263

Any help is appreciated


Update

I even tried Arbitrary uploads to true for transport security and the problem is still there.

Error Domain= Code=0 "Redirection to URL with a scheme that is not HTTP(S)" UserInfo={_WKRecoveryAttempterErrorKey=, NSErrorFailingURLStringKey=itms-appss://apps.apple.com/gb/app/xx-yy-zz/id435919263, NSErrorFailingURLKey=itms-appss://apps.apple.com/gb/app/xx-yy-zz/id435919263, NSLocalizedDescription=Redirection to URL with a scheme that is not HTTP(S)}

like image 671
dinesh R Avatar asked Nov 07 '19 11:11

dinesh R


People also ask

Is WKWebView the same as Safari?

WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.

What is the difference between UIWebView and WKWebView?

Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.

Is UIWebView deprecated?

As of iOS 12.0, 'UIWebView' has been explicitly marked as deprecated. Apple is encouraging developers to adopt WKWebView instead, which was introduced in iOS 8.0.

What is iOS WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.


1 Answers

I think you could try to intercept the itunes link in wkwebview's delegate methods and open the URL using openURL

The below source code will open any itms-appss links in wkwebview. Don't forget to conform to WKNavigationDelegate

   - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    if ([webURL.scheme isEqualToString:@"itms-appss"])
        {
                UIApplication *app = [UIApplication sharedApplication];
    if ([app canOpenURL:webURL])
    {
        [self.webviewObj stopLoading];
        [app openURL:[NSURL URLWithString:[webURL absoluteString]]];
        decisionHandler(WKNavigationActionPolicyCancel);
     } else{
        decisionHandler(WKNavigationActionPolicyCancel);
       }
        }
    else
       {
            decisionHandler(WKNavigationActionPolicyAllow);
        }
     return;
    }
like image 182
Durai Amuthan.H Avatar answered Nov 09 '22 06:11

Durai Amuthan.H