【问题标题】:Location Services in iOS 6 not workingiOS 6 中的定位服务不工作
【发布时间】:2013-02-05 15:07:07
【问题描述】:
- (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];
}

}

这是 ios 4 和 5 中的工作代码。我的问题是我无法在 ios 6 中获取位置。该应用程序甚至不请求用户许可。在阅读完这就是我到目前为止所尝试的:

  • CFBundleDisplayName 解决方案。我的 plist 中已经有了 CFBundleDisplayName。我尝试删除它并再次添加它 - 不行。

  • 将 Location Manager 的属性 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;
    }

我也读过locationManager:didUpdateLocations: ,我不知道如何在代码中实现它,我也不确定这是否是解决方案。

【问题讨论】:

    标签: ios objective-c cocoa-touch cocoa


    【解决方案1】:

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

    [locationManager startUpdatingLocation];
    

    【讨论】:

    • 是的,像这样:- (void)alertView:(UIAlertView *)anAlertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if(buttonIndex==1){ self.useMyLocation = YES; [[self locationManager] startUpdatingLocation]; }else{ // buttonIndex==0 self.useMyLocation = NO; [self locationUpdated]; } }
    • @Sha,您应该更新您的问题以包括 - 另外,是否曾经调用该函数来启动位置管理器更新?
    • 在低于 6 的 ios 中 - 是的。在 ios 6 上 - 我不知道也没有可以调试的带有 ios 6 的设备。我可以在模拟器上测试它吗? (无论我使用什么版本的模拟器,该函数都不会被调用)
    • 经过一些测试,我发现上面的方法没有被调用。我在另一个地方实现了[[self locationManager] startUpdatingLocation];,我可以看到它启动了,但应用程序仍然忽略它。
    • 你实现了 locationManager:didFailWithError: - 如果是的话,它被调用了吗?
    猜你喜欢
    • 2012-09-13
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2014-10-09
    相关资源
    最近更新 更多