简体   繁体   English

CLLocationManager的按钮操作(当前位置弹出)

[英]Button Actions for CLLocationManager(current location popup)

I am having small struggle in finding current location, while using CLLocationManager it will ask for one notification like "Would you like to use your current location" right.. In that there two options named: 1.OK 2.Dont Allow. 我在查找当前位置时遇到了一些小困难,使用CLLocationManager时,它将要求一个通知,例如“您想使用您的当前位置”。。在此,有两个选项名为:1.OK 2.Dont Allow。 Is it possible to write custom action for this two buttons... If anyone having any Idea to do this and related to this, then will be very useful for me.. 是否可以为这两个按钮编写自定义操作...如果有人有任何想法要执行并与此相关,那么对我来说将非常有用。

Thank's in advance... 提前致谢...

make method like this and attach it to your button or call it from viewDidLoad 这样的make方法并将其附加到您的按钮上,或从viewDidLoad调用它

-(void) showLocation
{
  // put an alerview to ask user for allow/disallow
}

// in alerView delegate methods, agains yes button enable user current location //在alerView委托方法中,再次使用yes按钮启用用户当前位置

I don't think you can override the actions for this alert. 我认为您无法覆盖此警报的操作。 However, you can implement CLLocationManager's delegate method 但是,您可以实现CLLocationManager的委托方法

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;

In there you can find out whether the user has enabled or not the location services for your app. 您可以在其中找到用户是否已为您的应用启用了位置服务。

Here's an example of an implementation for the above method 这是上述方法的实现示例

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

    [self.locationManager stopUpdatingLocation];
    switch([error code]) {
        case kCLErrorDenied:
            //User has not enabled location services for this app.
            break;
        case kCLErrorLocationUnknown:
            //location could not be found
            break;
        default:
            //some other issue
            break;
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error title"
                                                    message:@"An error message"
                                                    delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
    [alert show];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM