CLLocationManager AuthorizationStatus回调? [英] CLLocationManager AuthorizationStatus callback?

查看:544
本文介绍了CLLocationManager AuthorizationStatus回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我有一个名为发现"的标签. 发现"选项卡将使用用户的当前位置来查找他们附近的东西".我没有向用户提供一般的授权请求(根据研究通常会被拒绝),而是向用户提供了一个模态,解释了我们的要求.如果他们回答是",那么会弹出实际的授权"消息.

In my app I have a tab called "Discover". The Discover tab will use the users current location to find "stuff" near them. Instead of presenting the user with a generic Authorization Request (which typically gets declined, based on research), I present the user with a modal explaining what we're asking for. If they say yes, THEN the actual Authorization message pops up.

但是,用户仍然可以选择不显示提示.有没有一种方法可以在提示中添加回调,以便一旦用户选择一个选项,我就可以查看他们是否接受或拒绝了?

However, the user still has the option to say no the prompt. Is there a way to add a callback to the prompt so that once the user selects an option I can see if they accepted or declined?

我已经尝试过了:

func promptForLocationDataAccess() {
    locationManager.requestWhenInUseAuthorization()
    println("test")
}

正如预期的那样,"println"在请求提示出现的同时执行,所以我不能那样做.

As expected, the "println" executes at the same time that the request prompt comes up, so I can't do it that way.

问题在于,如果用户选择不使用位置数据,则所提供的内容将与他们接受的内容不同.

The problem is that if the user opts to not use Location Data, the content served will be different than if they had accepted.

理想情况下,我希望进行某种回调,但是在这一点上,我会采取任何逻辑上的指导!

Ideally I'm hoping for a callback of some kind, but I'll take any logical direction at this point!

推荐答案

您可以使用

You can use the locationManager:didChangeAuthorizationStatus: CLLocationManagerDelegate method as a "callback" of sorts.

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    if (status == kCLAuthorizationStatusDenied) {
        // The user denied authorization
    }
    else if (status == kCLAuthorizationStatusAuthorized) {
        // The user accepted authorization
    }
}

在Swift中(用户Michael Marvick建议进行更新,但由于某些原因而被拒绝...):

And in Swift (update suggested by user Michael Marvick, but rejected for some reason...):

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if (status == CLAuthorizationStatus.denied) {
        // The user denied authorization
    } else if (status == CLAuthorizationStatus.authorizedAlways) {
        // The user accepted authorization
    } 
}

这篇关于CLLocationManager AuthorizationStatus回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆