我希望每X秒获得一次用户坐标
我添加了进入app delegate的位置。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
...
这里我处理新的坐标
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *loc = [locations objectAtIndex:0];
NSDate* eventDate = loc.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (howRecent < 10)
{
CLLocation* location = [locations lastObject];
double lat = location.coordinate.latitude;
double lng = location.coordinate.longitude;
NSLog(@"lat:%f lng:%f", lat, lng);
...
但是当应用程序处于后台时,我不知道如何继续获取iPhone坐标。 我想我应该添加一些代码:
- (void)applicationDidEnterBackground:(UIApplication *)application...
但我不知道如何让位置变为现场?
答案 0 :(得分:2)
在您的info.plist中:
R.Click - &gt;添加一行,然后选择Required background modes
- &gt;在第0项中选择App registers for location updates