Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkwebview with location services

Ive been experimenting with swift and wanted to try out the wkwebview. Ive built an app and it all works correctly but the problem is that the webpage that i load into my wkwebview uses google maps and requires location services, so the javascript should prompt a message saying "this app requires your location information". The swift app wkwebview doesnt display any message doesnt display my google maps either. If i visit the url with the safari browser it prompts the location message and also in uiwebview on ios 7 it promps that message. Anyone else come accross this and know a solution?

like image 284
Zolve Avatar asked Sep 24 '14 14:09

Zolve


People also ask

Is WKWebView 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 WKWebView deprecated?

Since then, we've recommended that you adopt WKWebView instead of UIWebView and WebView — both of which were formally deprecated. New apps containing these frameworks are no longer accepted by the App Store.

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

In iOS 8, you need to have a key in your Info.plist that the system can use to prompt for location usage. In your case you want to add a key/value pair with key NSLocationWhenInUseUsageDescription. The value of that pair will be shown in the first popup, from the system, asking if your app can access location services. Then Google Maps will be allowed to pop up its own alert.

Info.plist

like image 118
Nate Cook Avatar answered Sep 28 '22 06:09

Nate Cook