开发者

Core Location while iPhone locked

开发者 https://www.devze.com 2022-12-21 05:39 出处:网络
I was reading your comment below: \"I don\'t know what you mean by \"power save\" mode, but if you\'re thinking of when the screen is locked/off, that does not stop Core Location from running if your

I was reading your comment below:

"I don't know what you mean by "power save" mode, but if you're thinking of when the screen is locked/off, that does not stop Core Location from running if your app is still running. On the contrary it's easy to run down your phone's battery much more quickly than you'd expect if you lock the phone while an app that uses Core Location is running, because the phone will continue to update the app as new location data is available. You could avoid this in your application by listening for UIApplicationWillResignActiveNotification to detect the screen locking, and UIApplicationDidBecomeActiveNotification to detect unlock."

I have an app that uses core location, and as long as my phone is not locked, I get regular NSlog entries from core location. The moment I lock it though, the NSlogs from core location stop until I wake the phone. My code that does the logging is:

-(void) locationManager:(CLLocationManager *)manager 
 didUpdateToLocation:(CLL开发者_StackOverflow社区ocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation {

 if (startingPoint == nil) 
  self.startingPoint = newLocation;

 userLocation.latitude = newLocation.coordinate.latitude;
 userLocation.longitude = newLocation.coordinate.longitude;

 NSLog(@"Update from LM: Latitude = %f",newLocation.coordinate.latitude);
 NSLog(@"                Longitude = %f",newLocation.coordinate.longitude);

}

Am I missing something?


That looks like part of a response that I wrote to a question over a year ago. See my comment there about it.

For future reference, if you're going to write a response to an answer, you shouldn't create a new question. Stack Overflow has a comment feature that's designed for this purpose. Saying "your comment" with no context at all is asking for confusion (I just happened to read Stack Overflow today, or I wouldn't have noticed).

0

精彩评论

暂无评论...
验证码 换一张
取 消