2

I am new to Swift and WKWebView.

I have a WKWebView implemented in my App. I want to show a website in it which uses the location like https://www.google.com/maps.

I added NSLocationWhenInUseUsageDescription in Info.plist.

When I first open the app there is a prompt which asks for the location.

When I click Allow the app crashes with the Thread 1: signal SIGABRT error.

I checked all my outlets and there is definitely no mistake.

Also the error displays:

UIAlertView is deprecated and unavailable for UIScene based applications, please use UIAlertController!

But I'm not explicitly call a UIAlertView so I don't know how to fix this.

Soteri
  • 327
  • 4
  • 21

3 Answers3

3

Me too, this sucks.

 *** Terminating app due to uncaught exception 'NSObjectNotAvailableException', reason: 'UIAlertView is deprecated and unavailable for UIScene based applications, please use UIAlertController!'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23b98bde __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff503b5b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23b98a1c +[NSException raise:format:] + 188
    3   UIKitCore                           0x00007fff466e9463 -[UIAlertView initWithFrame:] + 417
    4   UIKitCore                           0x00007fff466e9ad0 -[UIAlertView initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:] + 218
    5   UIKitCore                           0x00007fff47516acf +[UIAlertView(ViewServiceSupport) _alertViewForWindow:] + 217
    6   UIKitCore                           0x00007fff476cdb44 -[UIWebGeolocationPolicyDecider _executeNextChallenge] + 242
    7   WebKit                              0x00007fff2d123a6d _ZN6WebKit43decidePolicyForGeolocationRequestFromOriginEPN7WebCore14SecurityOriginERKN3WTF6StringEPU37objcproto26WebAllowDenyPolicyListener11objc_objectP8UIWindow + 169
    8   WebKit                              0x00007fff2d123641 -[WKGeolocationProviderIOS(WebGeolocationCoreLocationUpdateListener) geolocationAuthorizationGranted] + 603
    9   WebKit                              0x00007fff2d12328d -[WKGeolocationProviderIOS
...
Johan Forssell
  • 333
  • 4
  • 6
0

Its funny you don't get this error with the "location always" description. but you never get a location...

I have downgraded my app to target platform "iOS 12" not 13, this then allows a second "Alert" from WKWebView to use location data. I could not work out how to provide a UIAlertControl instead of the UIAlertView the WKWebView is asking for.

There is a lot of people complaining on the web about the updates done in iOS 13, and how many frameworks and libraries have been affected by the changes.

Adam Marshall
  • 5,895
  • 2
  • 22
  • 22
0

You can intercept alert in javascript, example how to just deny permission request:

 let removeLocationJS = """
 navigator.geolocation.getCurrentPosition = function(success, error, options) {
     error({
         PERMISSION_DENIED: 1,
         code: 1
     });
 };
 """

 let removeLocation = WKUserScript(source: removeLocationJS, injectionTime: .atDocumentStart, forMainFrameOnly: true)
 contentController.addUserScript(removeLocation)

 let config = WKWebViewConfiguration()
 config.userContentController = contentController

 let webView = WKWebView(frame: .zero, configuration: config)

Code snippet from @aranasaurus POST

How to handle location permission instead of denied it, described HERE

user3626411
  • 188
  • 2
  • 3
  • 15