我正在尝试获取一个位置并将其与在线位置进行比较所有在后台发生的我创建的方法使用后台位置服务工作正常但大约一分钟后状态栏中的位置图标消失并且该方法不再被调用
这是代码
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
double lat = newLocation.coordinate.latitude;
double lon = newLocation.coordinate.longitude;
NSURL * locationURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://somedomainname.com/iphoneLocation?lat=%f&lon=%f",lat,lon]];
NSData * responseData = [NSData dataWithContentsOfURL:locationURL];
NSString* aStr;
aStr = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
if ([aStr isEqualToString:@"out Of Any Knowen Range"] ){
UILocalNotification *notify =[[UILocalNotification alloc] init];
notify.alertAction = [[NSString alloc] initWithString: @"View"];
notify.fireDate=nil;
notify.alertBody = [NSString stringWithFormat:@"New Data Occured"];
notify.soundName = UILocalNotificationDefaultSoundName;
NSLog(@"Local notification should display");
[[UIApplication sharedApplication] presentLocalNotificationNow:notify];
}
}
在 viewDid 加载中我正在使用类似这样的东西
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
CLLocation *userLocation = [locationManager location];
那有什么问题