【问题标题】:WKWebView Thread 1: signal SIGABRT when using locationWKWebView 线程 1:使用位置时发出 SIGABRT 信号
【发布时间】:2020-01-30 13:41:04
【问题描述】:

我是 Swift 和 WKWebView 的新手。

我在我的应用程序中实现了一个 WKWebView。我想在其中显示一个使用 https://www.google.com/maps 之类的位置的网站。

我在Info.plist 中添加了NSLocationWhenInUseUsageDescription

当我第一次打开应用程序时,会出现一个询问位置的提示。

当我点击Allow 时,应用程序崩溃并出现Thread 1: signal SIGABRT 错误。

我检查了所有网点,绝对没有错误。

也显示错误:

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

但我没有明确调用UIAlertView,所以我不知道如何解决这个问题。

【问题讨论】:

  • 用这个去哪里?相机权限有效,但任何位置权限都会使应用程序崩溃。
  • 很遗憾没有:(
  • 我已将我的应用程序定位到 iOS 版本 12,尽管已弃用它允许 UIAlertView 弹出
  • @Soteri 对此有何线索?我的应用也因为同样的原因而崩溃。
  • 解决方案有什么更新吗?同样的问题。

标签: javascript ios swift xcode wkwebview


【解决方案1】:

您可以在 javascript 中拦截警报,例如如何拒绝权限请求:

 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)

来自@aranasaurus POST的代码sn-p

如何处理位置权限而不是拒绝它,描述HERE

【讨论】:

    【解决方案2】:

    有趣的是,“位置始终”描述中没有出现此错误。但你永远找不到位置...

    我已将我的应用程序降级为目标平台“iOS 12”而不是 13,这将允许来自 WKWebView 的第二个“警报”使用位置数据。我不知道如何提供UIAlertControl 而不是WKWebView 要求的UIAlertView

    网上有很多人抱怨 iOS 13 的更新,以及有多少框架和库受到这些更改的影响。

    【讨论】:

      【解决方案3】:

      我也是,这太糟糕了。

       *** 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
      ...
      

      【讨论】:

      • 我已将我的应用程序定位到 iOS 版本 12,尽管已弃用它允许 UIAlertView 弹出
      • @johan 你找到解决方案了吗?我在最新的 iOS 上遇到了同样的错误。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多