【问题标题】:iphone location service alert call back allow and don't allow handlingiphone位置服务警报回调允许和不允许处理
【发布时间】:2015-01-30 12:05:13
【问题描述】:

我有一个按钮,点击后我授权我的应用启用定位服务。我想从警报中捕获允许按钮事件。当用户按下允许时,我的按钮颜色将变为其他颜色。我无法捕获 allow 按钮的回调。但是,我可以在此链接的帮助下捕获 不允许 按钮事件

Location service iOS alert call back

请谁能告诉我如何捕捉允许按钮的点击,成功后我想做我的代码。

【问题讨论】:

    标签: objective-c iphone ios8 mapkit cllocationmanager


    【解决方案1】:

    实现这个:

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
        if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
            //allowed - do your logic
        }
        else if (status == kCLAuthorizationStatusDenied) {
            //denied
        }
    }
    

    斯威夫特 4/5

    self.locationManager.requestAlwaysAuthorization()
    

    然后在委托方法中处理:

    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!")
        }    
    }
    

    记得设置locationManager委托:

    self.locationManager.delegate = self;
    

    并由您的班级实施CLLocationManagerDelegate

    【讨论】:

    • @Rajan 你的问题解决了吗?如果否,请提供更多详细信息,如果是,请考虑接受答案。
    • KlimczakM 。谢谢。它解决了我的问题。抱歉,我在很多天后登录 stackoverflow 时接受晚了。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    相关资源
    最近更新 更多