我在我的应用程序中使用台风框架。我的申请工作正常。现在我想在我的应用中定位更新。我添加了Location框架并实现了代码。 但是我的CLLocationManger委托方法无效。
我在demo app中复制了相同的代码,没有任何依赖关系,相同的代码开始工作,我可以获得位置更新。
有谁能告诉我这种行为的可能原因是什么。
以下是我正在使用的代码:
在我的LoginViewController.m中我使用以下代码 - (void)viewDidLoad方法
if (![CLLocationManager locationServicesEnabled]) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Location Services Disabled", nil)
message:NSLocalizedString(@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil] show];
} else {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
}
答案 0 :(得分:0)
这与Typhoon无关。我们不知道框架中会阻止CLLocationManager正常工作的任何内容。此外,商店中有许多已发布的应用程序正在使用位置服务。实际上,the very first Typhoon application使用了位置服务。
位置管理员的一个常见问题是忘记告诉它开始发送更新。请务必执行以下操作:
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation]; //This is required!
[_locationManager startUpdatingHeading]; //This is required!
如果你希望你也可以在Typhoon中建立一个位置管理器并注入它,只要调用上面的步骤来开始更新。
答案 1 :(得分:0)
对Typhoon不确定,但请确保你在经理的整个生命周期内保持对管理员的强烈引用,当然要正确地指派其代表。