Location Access Issue with WKWebView - iOS 17+

225 views Asked by At

The website does not receive location permissions despite the user accepting the permissions. The problem occurs only on iOS 17+. In earlier versions, two alerts were displayed that included requests for location permissions.

This is the ViewController displaying Google Maps where the problem occurs.

import UIKit
import WebKit

class ViewController: UIViewController {
    var webView: WKWebView?
    
    override func viewDidLoad() {
        webView = WKWebView(frame: self.view.bounds)
        view.addSubview(webView!)
        
        if let url = URL(string: "https://www.google.com/maps/preview?hl=en") {
            let request = URLRequest(url: url)
            webView?.load(request)
        }
    }
}

When the app goes into the background and then reappears in the foreground, the missing alert appears. Link for video: https://drive.google.com/file/d/1VkmjIOnv87jqn5ZMOsYiASX6DQCDDgLA/view?usp=sharing

I have the NSLocationWhenInUseUsageDescription key added to Info.plist in the project. I tried to track the authorizationStatus change when CLLocationManager detects that the authorization has been granted and reload the page. This works, but unfortunately only partially.

Have any of you had a similar problem, or have an idea how to force the missing alert to be displayed without going into the background in the app and re-entering the foreground?

0

There are 0 answers