代码之家  ›  专栏  ›  技术社区  ›  Mladen

如何知道位置服务对话框是否在iOS中显示?

  •  0
  • Mladen  · 技术社区  · 8 年前

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

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

    (图像取自 here .)

    Location Services prompt dialog

    1 回复  |  直到 8 年前
        1
  •  2
  •   Reinier Melian    8 年前

    检查 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
        }