Introduction: What are location services in general?
Location services are the technologies that provide information about a person’s location. They can be used to track someone and also to provide relevant information.
Some of the most common location services are GPS, geolocation, and cell tower identification. These technologies can be used for various purposes, such as tracking people, delivering relevant offers based on location, or even finding your lost phone.
How do location services work in HTML5?
How about HTML5 Geolocation in WebView-based apps on iOS?
The iOS webview location permission prompt is a particular case: The prompt appears when you are using the webview to view a website and asks for permission to use your current location.
The prompt can be declined by tapping “Don’t Allow”. This will stop the app from accessing your location data, but it will disable the web app’s features, like geolocation-based searches and maps within the webview. But there is a problem. When a user first installs an iOS app with WebView location-based services enabled, the app will ask for location permission and then give you a prompt to allow or deny each time you open a page in the view. This differs from how Android handles this prompt, where you’re only prompted once when installing the app. So on iOS, this location permission request comes every single time the website requests the app for the first time (after app launch) and in addition to the general permission dialog for the app. This procedure creates a kind of double permission dialog that also reveals the URL and the app as a WebView app.
The solution for double location prompts in WKWebView-based apps
So how to prevent your WKWebView-based app from repeatedly asking for permission again and again? Good news: The new WebViewGold update (Swift app template for Xcode) from August 2022 has introduced a prompt that only once asks for permission to access the customer’s location (and even without revealing the URL). After allowing, the user will never be asked again, even after a complete restart of the app. So when a user first installs a WebViewGold-based app from the Apple App Store, the app will ask for location permission at first run, then never again. This will work if the geolocation API is triggered using a button or a link.