【问题标题】:How to know if Location Service dialog was shown in iOS?如何知道位置服务对话框是否在 iOS 中显示?
【发布时间】:2017-11-20 14:02:27
【问题描述】:

据我了解,下图中的对话框仅在应用第一次请求位置时显示。无论用户选择什么选项(允许或不允许),此对话框都不会再次显示给用户。

  • 有没有办法知道定位服务提示对话框是否已在 iOS 中显示?
  • 我还想编写一些 UI 测试,所以我需要能够在每次运行测试时显示此对话框。我可以以某种方式(通过模拟或其他方式)吗?

(图片取自here。)

【问题讨论】:

    标签: ios swift location-services


    【解决方案1】:

    在此枚举中检查CLAuthorizationStatus,您可以找到一个名为notDetermined 的值,当用户尚未做出选择时会返回该值。

    // User has not yet made a choice with regards to this application
    case notDetermined
    

    示例

        if(self.locationManager.authorizationStatus == .notDetermined)
        {
            //Do whatever you want here
        }
    

    【讨论】:

    • 谢谢。有没有办法可以模拟 .authorizationStatus 在 UI 测试(不是单元测试)中始终返回 .notDetermined 状态?
    • 对此我不确定,但乍一看,我认为.autorizationStatus 是只读变量,只能通过CLLocationManager requestAlwaysAutorization 方法或requestInUseAutorization 方法@lagoman 更改如果您在这个主题上有一些进展,请告诉我
    猜你喜欢
    • 1970-01-01
    • 2011-12-16
    • 2015-08-17
    • 2015-04-17
    • 2020-01-11
    • 1970-01-01
    • 2011-01-29
    • 2013-07-06
    • 1970-01-01
    相关资源
    最近更新 更多