【发布时间】:2012-06-25 23:10:58
【问题描述】:
我正在尝试获取位置并将其与在线位置进行比较,所有这些都是在后台发生的 我创建的方法使用后台位置服务运行良好,但大约一分钟后,状态栏中的位置图标消失,并且不再调用该方法
这里是代码
- (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];
那有什么问题
【问题讨论】:
标签: iphone ios geolocation location locationmanager