本文介绍了位置服务在iOS 6不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 - (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解决方案。我已经有CFBundleDisplayName在我的plist。 将位置管理器的属性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: code>,我不知道如何在代码中实现它,也不知道如果这是解决方案。解决方案 [locationManager startUpdatingLocation]; - (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. After reading around this is what I've tried so far:CFBundleDisplayName solution. I already had CFBundleDisplayName in my plist. I tried removing it and adding it again - no go.setting the property pausesLocationUpdatesAutomatically of Location Manager to NO like this:...- (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. 解决方案 Do you ever start the location manager?[locationManager startUpdatingLocation]; 这篇关于位置服务在iOS 6不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-13 22:24
查看更多