【问题标题】:Swift Pre-permission OverlaySwift 预许可覆盖
【发布时间】:2018-05-24 12:16:54
【问题描述】:

在我获取用户位置的函数中,我创建了预权限,以便在授权消息之前发出警报,以免失去从用户那里获得必要权限的 1 机会。

func getCurrentLocation() {
// Init LocationManager
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = 
kCLLocationAccuracyThreeKilometers;

let alert = UIAlertController(title: "Allow Loction Services?",
message: "This allows the app to your loction",
preferredStyle: .alert)

let ok = UIAlertAction(title: "Allow", style: .default, handler: { 
(action) -> Void in
self.showHUD("loading...")

if locationManager.responds(to: 
#selector(CLLocationManager.requestWhenInUseAuthorization)) {
locationManager.requestAlwaysAuthorization()
}}
self.hideHUD()
)
}



let cancel = UIAlertAction(title: "Not Now", style: .destructive, 
handler: { (action) -> Void in })

alert.addAction(ok); alert.addAction(cancel)
present(alert, animated: true, completion: nil)

locationManager.startUpdatingLocation()
}

在该部分:

let ok = UIAlertAction(title: "Allow", style: .default, handler: { (action) -> Void in self.showHUD("loading...")

一个错误提示我们“表达式类型不明确,没有更多上下文”

【问题讨论】:

    标签: swift xcode permissions cllocationmanager uialertcontroller


    【解决方案1】:

    Swift 编译器给出了这个错误,因为语句 self.hideHUD() 位于标记完成处理程序块的大括号之外。

    我怀疑上面一行不是两个花括号,而是一个花括号,另一个花括号之后隐藏HUD:

    .......
            locationManager.requestAlwaysAuthorization()
        }
        self.hideHUD()
    }
    ........
    

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多