作者:深tp悟人生 | 来源:互联网 | 2023-05-24 12:00
我有一个按钮,其中点击我授权我的应用程序启用位置服务.我想从警报中捕获允许按钮事件.当用户按下允许时,我的按钮颜色将变为其他颜色.我无法捕获允许按钮的回调.但是,我可以通过此链接捕获不允许按钮事件
位置服务iOS提醒回电
请任何人都可以告诉我如何捕获允许按钮点击并成功我想要我的代码.
1> KlimczakM..:
实现这个:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
//allowed - do your logic
}
else if (status == kCLAuthorizationStatusDenied) {
//denied
}
}
Swift 2.2:
self.locationManager.requestAlwaysAuthorization()
Swift 3.0:
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .notDetermined:
manager.requestAlwaysAuthorization()
case .restricted, .denied:
// location services unauthorized
case .authorizedAlways, .authorizedWhenInUse:
manager.startUpdatingLocation()
@unknown default:
print("New CLLocationManager.authorizationStatus() not handled!")
}
}
记得设置你的代表:
self.locationManager.delegate = self;
并由您的班级实现: locationManager