'Redirection to App store from my app not working on iPhone 7 plus

I have a UIButton which redirects to another app link on an App Store, At first, it is not redirecting to the app store it was just loading in the in-app browser(Webview) so to fix this I have added urlschemes to verify if it is app store redirection then redirect app store Following code I have added.

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    if urlString.contains(urlString.contains("itms-apps://") {
        if let url = navigationAction.request.url, UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)

            decisionHandler(.cancel)
        } else {
            decisionHandler(.allow)
        }
    } else {
        decisionHandler(.allow)
    }
}

The issue I am facing is that I am not able to redirect to the app store on iPhone7 plus(iOS 15.0) device, on other devices, it is working fine. I am not sure if it is a device-specific issue am not able to find any solution to fix it on 7 plus devices.

I am using Xcode 13.0 version, iPhone 7 Plus iOS 15



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source