Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

objective c - iOS7 Core Location not updating

I have a very simple app example that initialises and updates the users location.. On device it successfully throws another callback location every second or so however on device (iPhone running iOS7) is calls the method once and then mysteriously stops...

//Setup Location Manager in ViewDidLoad
locationManager = [[CLLocationManager alloc] init];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
     NSLog(@"location services not turned on");
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
     NSLog(@"loactions %@", locations);
}

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{

    NSLog(@"new location %f, and old %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}

In iOS6 this app worked perfectly and continuously updated the devices location... What has changed since iOS7?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are a few things here:

1- I don't see anywhere the property: pausesLocationUpdatesAutomatically. The default for this property is Yes. This means that depending on your activityType (see #2) below, the GPS will pause updates and this could be the reason you are not getting updates. The algorithm is a black box that only Apple knows and maybe it somehow changed between iOS6 and iOS7. Setting pausesLocationUpdatesAutomatically to NO can impact the battery.

2- You should set your activityType depending on your application. The default is CLActivityTypeOther which I am not sure how it impact the GPS algorithm and #1 above. So in order to test your app initially, I would set the activityType appropriately and change pausesLocationUpdatesAutomatically to No. In my test, I would get an update about every second consistently (I tested it overnight).

3- Location updates testing requires movement. In order to get better results, I would use the activityType you set, for testing. In other words, if activityType is CLActivityTypeFitness, I would walk around to test it, etc..

4- locationManager didUpdateToLocation fromLocation is deprecated in iOS7. In addition if locationManager didUpdateLocations is implemented, the former will not be called. So in your case above, locationManager didUpdateToLocation fromLocation is not being called.

5- There is no real battery usage difference between kCLLocationAccuracyBestForNavigation and kCLLocationAccuracyBest. On the other hand, kCLLocationAccuracyBestForNavigation uses top speed GPS and in addition combines it with accelerometer data.

So I would start with setting activityType, setting pausesLocationUpdatesAutomatically to NO and changing desiredAccuracy to kCLLocationAccuracyBestForNavigation. Once you are getting continuous updates, then I would set pausesLocationUpdatesAutomatically to Yes and try to work the code to achieve the same app usability.

Hope this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...