简体   繁体   English

iOS 6中的位置服务无法正常工作

[英]Location Services in iOS 6 not working

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{
    static int i=0;
    if([self getCurrentLocation]==nil){
        i++;
        if(i>3){
            [[self locationManager] stopUpdatingLocation];
            useMyLocation = NO;
            [self locationUpdated];
        }
    }else{
        [self locationUpdated];
    }
}

- (void)alertView:(UIAlertView *)anAlertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==1){
    self.useMyLocation = YES;
    [[self locationManager] startUpdatingLocation];
}else{ // buttonIndex==0
    self.useMyLocation = NO;
    [self locationUpdated];
}

} }

This is a working code in ios 4 and 5. My problem is that I can't get location to work in ios 6. The app doesn't even asks for permission from the user. 这是ios 4和5中的有效代码。我的问题是,我无法在ios 6中获得工作位置。该应用程序甚至没有征求用户的许可。 After reading around this is what I've tried so far: 读完之后,这是我到目前为止尝试过的:

  • CFBundleDisplayName solution. CFBundleDisplayName解决方案。 I already had CFBundleDisplayName in my plist. 我的plist中已经有CFBundleDisplayName。 I tried removing it and adding it again - no go. 我尝试将其删除并再次添加-不行。

  • setting the property pausesLocationUpdatesAutomatically of Location Manager to NO like this: 将位置管理器的属性pausesLocationUpdatesAutomatically自动设置为NO,如下所示:

... ...

- (CLLocationManager *)locationManager{
        if (locationManager != nil){
            return locationManager;
        }   
        CLLocationManager *tmp = [[CLLocationManager alloc] init];
        tmp.pausesLocationUpdatesAutomatically = NO;  //!@#
        [self setLocationManager:tmp];
        [tmp release];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        [locationManager setDelegate:self];
        return locationManager;
    }

I also read about locationManager:didUpdateLocations: , I didn't know how to implement it in the code, also i'm not sure if that's the solution. 我还阅读了有关locationManager:didUpdateLocations: ,我不知道如何在代码中实现它,我也不知道这是否是解决方案。

您是否曾经启动过位置管理器?

[locationManager startUpdatingLocation];

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

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