【发布时间】:2014-09-04 18:49:34
【问题描述】:
我的应用需要位置数据才能运行。我确保用户在登录之前必须接受我的应用的位置服务。如果用户拒绝,它将阻止用户登录,直到用户授予应用使用位置服务的权限。
除了 1 个测试用户的设备外,一切都运行良好。即使用户授予应用位置服务权限,设备也根本没有获取位置数据。没有出现 GPS 图标。谷歌地图在用户的设备上运行良好。我真的不确定这里发生了什么。看起来didUpdateToLocation 根本没有在此用户的设备上调用。什么可能导致此问题?
代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self getCurrentLocation];
...
}
- (void)getCurrentLocation {
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 100; // meters
[locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
[self setLatitude:[NSNumber numberWithFloat:currentLocation.coordinate.latitude]];
[self setLongitude:[NSNumber numberWithFloat:currentLocation.coordinate.longitude]];
if (loginController) {
[loginController validateSession];
loginController = nil;
}
}
}
【问题讨论】:
-
如果您在设备中尝试,请删除 locationManager.distanceFilter = 100;因为在您的手机每步行 100 米后调用 didupdate location 方法进行测试,您可以将其移除
标签: ios iphone gps location cllocationmanager