CLLocationManagerDelegate委托在8.1中未调用iOS
我在静态库中使用CLLocationManagerDelegate,当我在iOS 7设备上运行时,一切都很好,但当我在另一台iOS 8.1.3设备上测试它时,委托方法不会被调用。 我赚了一大笔钱 @属性(非原子,强)CLLocationManager locationManager 我还在info.plist中添加了相应的键和字符串值(NSLocationAlwaysUsageDescription,requestAlwaysAuthorization) 这就是我的例子CLLocationManagerDelegate委托在8.1中未调用iOS,ios,objective-c,location,static-libraries,cllocationmanager,Ios,Objective C,Location,Static Libraries,Cllocationmanager,我在静态库中使用CLLocationManagerDelegate,当我在iOS 7设备上运行时,一切都很好,但当我在另一台iOS 8.1.3设备上测试它时,委托方法不会被调用。 我赚了一大笔钱 @属性(非原子,强)CLLocationManager locationManager 我还在info.plist中添加了相应的键和字符串值(NSLocationAlwaysUsageDescription,requestAlwaysAuthorization) 这就是我的例子 self.locatio
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager setDelegate:self];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
}
[self.locationManager startUpdatingLocation];
请帮助我找出为什么没有调用委托方法!!
为什么我没有得到位置更新 我希望这对你有帮助。调用
[locationManager RequestWhenUseAuthorization]
内部if()…
if ([CLLocationManager locationServicesEnabled])
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
}
else{
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be showing past informations. To enable, Settings->Location->location services->on" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Continue",nil];
[servicesDisabledAlert show];
[servicesDisabledAlert setDelegate:self];
}
- (void)requestWhenInUseAuthorization
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
// If the status is denied or only granted for when in use, display an alert
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
NSString *title;
title = (status == kCLAuthorizationStatusDenied) ? @"Location services are off" : @"Background location is not enabled";
NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings";
UIAlertView *alertViews = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Settings", nil];
[alertViews show];
}
// The user has not enabled any location services. Request background authorization.
else if (status == kCLAuthorizationStatusNotDetermined) {
[locationManager requestWhenInUseAuthorization];
}
}
if ([alertView.message isEqualToString:@"To use background location you must turn on 'Always' in the Location Services Settings"])
{
if (buttonIndex == 1)
{
// Send the user to the Settings for this app
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL];
}
}
您必须添加
NSLocationAlwaysUsageDescription或nsLocationWhenUsageDescription在您的Plist文件中,带有一些消息“此应用程序需要您的位置”
我希望这对你有帮助。调用
[locationManager RequestWhenUseAuthorization]
内部if()…
if ([CLLocationManager locationServicesEnabled])
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
}
else{
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be showing past informations. To enable, Settings->Location->location services->on" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Continue",nil];
[servicesDisabledAlert show];
[servicesDisabledAlert setDelegate:self];
}
- (void)requestWhenInUseAuthorization
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
// If the status is denied or only granted for when in use, display an alert
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
NSString *title;
title = (status == kCLAuthorizationStatusDenied) ? @"Location services are off" : @"Background location is not enabled";
NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings";
UIAlertView *alertViews = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Settings", nil];
[alertViews show];
}
// The user has not enabled any location services. Request background authorization.
else if (status == kCLAuthorizationStatusNotDetermined) {
[locationManager requestWhenInUseAuthorization];
}
}
if ([alertView.message isEqualToString:@"To use background location you must turn on 'Always' in the Location Services Settings"])
{
if (buttonIndex == 1)
{
// Send the user to the Settings for this app
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL];
}
}
您必须添加
NSLocationAlwaysUsageDescription或nsLocationWhenUsageDescription在您的Plist文件中,带有一些消息“此应用程序需要您的位置”
对于iOS 8,您需要在Info.plist中定义“隐私-位置使用说明” 例如,隐私-位置使用说明=“使用您的位置显示附近的商店”
此键指定访问用户位置信息的原因。对于iOS 8,您需要在Info.plist中定义“隐私-位置使用说明”
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:5];
[locationManager setHeadingFilter:5];
[locationManager setDelegate:self];
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
例如,隐私-位置使用说明=“使用您的位置显示附近的商店”
此键指定访问用户位置信息的原因。您能在控制台输出中看到类似以下消息的内容吗
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:5];
[locationManager setHeadingFilter:5];
[locationManager setDelegate:self];
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我第一次将我的应用程序移植到iOS8时遇到了这个问题。定义以下键有一个新的限制
/* Localized versions of Info.plist keys */
"NSLocationWhenInUseUsageDescription" = "for some reason, your app will use your location whenever the app is in foreground";
"NSLocationAlwaysUsageDescription" = "for some reason, your app will use your location whenever the app is in background";
这些键必须在项目根目录中名为InfoPlist.strings的可本地化字符串文件中定义。有一次我把这个文件放错了位置,花了很长时间才弄清楚问题出在哪里
下一件事是,您应该检查您请求授权的CLLocationManager的生存期是否未超过处理用户确认的时间。例如,在AppDelegate中定义全局CLLocationManager
我希望这有帮助,
亲切问候,,
Peter您能在控制台输出中看到类似以下消息的内容吗
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我第一次将我的应用程序移植到iOS8时遇到了这个问题。定义以下键有一个新的限制
/* Localized versions of Info.plist keys */
"NSLocationWhenInUseUsageDescription" = "for some reason, your app will use your location whenever the app is in foreground";
"NSLocationAlwaysUsageDescription" = "for some reason, your app will use your location whenever the app is in background";
这些键必须在项目根目录中名为InfoPlist.strings的可本地化字符串文件中定义。有一次我把这个文件放错了位置,花了很长时间才弄清楚问题出在哪里
下一件事是,您应该检查您请求授权的CLLocationManager的生存期是否未超过处理用户确认的时间。例如,在AppDelegate中定义全局CLLocationManager
我希望这有帮助,
亲切问候,,
彼得
并将以下代码添加到.plist文件中
NSLocationAlwaysUsageDescription=Application would like to use your location
并将以下代码添加到.plist文件中
NSLocationAlwaysUsageDescription=Application would like to use your location
这将调用CLLocationManager的所有委托方法。这将调用CLLocationManager的所有委托方法。是否将代码从
requestwhenUseAuthorization
更改为您的requestAlwaysAuthorization
在-(void)locationManager:(CLLocationManager*)中标记断点更新位置:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation这是由[locationManager RequestWhenUseAuthorization]调用的;
根本没有发生任何事情,因为委托方法根本没有得到调用,只需在接口CLLocationManager*locationManager;
中的.h文件@property中声明即可(非原子,保留)CLLocationManager*locationManager;
或在.m文件界面中CLLocationManager*locationManager;
是否将代码从使用授权时的请求更改为您的requestAlwaysAuthorization
在-(void)locationManager:(CLLocationManager*)中标记断点manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
委托由[locationManager RequestWhenUseAuthorization]调用;
什么也没有发生,因为委托方法根本没有得到调用,只需在接口CLLocationManager*locationManager;
中的.h文件@属性中声明(非原子,保留)CLLocationManager*locationManager;
或在.m文件界面中CLLocationManager*locationManager;
谢谢peter的回答,但我的控制台中没有收到任何错误消息:/我已在plist中添加了此键,在appDelegate中也添加了CLLocation,但我始终有一个空值CLLocationManager和never获取位置..谢谢peter的回答,但我的控制台中没有收到任何错误消息:/i已经在plist中添加了此键,在appDelegate中也添加了CLLocation,但我始终有CLLocationManager的空值,并且从未获取位置..这对med很有帮助。问题的键是nsLocationWhenUsageDescription
帮助医疗。问题的关键是nslocationwhenUsageDescription
。