2014-10-16 53 views
1
我有 startMonitoringSignificantLocationChanges问题

接收当使用下面的代码,我的iOS 8的物理设备和模拟器位置,从不打didUpdateLocations方法:startMonitoringSignificantLocationChanges从未在<code>iOS 8</code></p> <p>iOS8上

-(void)viewDidLoad { 
     if (self.locationManager==nil) { self.locationManager = [[CLLocationManager alloc] init]; } 
     self.locationManager.activityType = CLActivityTypeFitness; 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
     self.locationManager.delegate = self; 
     if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { 
      NSLog(@“requestAlwaysAuthorization”); 
      [self.locationManager requestAlwaysAuthorization]; 
     } 
     [self.locationManager startMonitoringSignificantLocationChanges]; 

    } 

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 
     NSLog(“didUpdateLocation”); 
    } 

如果我将startMonitoringSignificantLocationChanges替换为startUpdatingLocation,物理设备接收到一个更新(这不是我期望的),但模拟器继续接收不断更新(这是我期望的,但不是我想要的)。

有关如何解决此问题的任何想法将不胜感激。我也宁愿用requestWhenInUseAuthorization代替requestAlwaysAuthorization,但我看别的地方,如果我想使用startMonitoringSignificantLocationChanges,我需要使用requestAlwaysAuthorization

回答

2

你必须定义你的plist文件的描述字符串键NSLocationAlwaysUsageDescription

<key>NSLocationAlwaysUsageDescription</key> 
<string>With this mode, you will never miss location updates!</string> 
+0

我'NSLocationWhenInUseUsageDescription',但并没有意识到有一个单独的'NSLocationAlwaysUsageDescription'关键。谢谢。 – Chris 2014-10-17 17:38:25

相关问题