[英]Cannot get location services working with Swift and iOS8 with NSLocationWhenInUseUsageDescription
[英]Location services not working in ios8
我现在已经挣扎了几天,但无法解决我的问题(尽管此处提供了所有信息)。 对不起,很抱歉。
在我的应用中,位置服务在iOS 8中停止工作。在此版本之前,一切正常。 我在这里阅读到,必须在deplist文件中有一些键,并且必须使用外部编辑器进行设置。
这里是:
但是它仍然无法正常工作。 在模拟器中或在我的设备上,不会提示我。
我也知道在文件中添加一些代码。 我应该添加什么代码,我应该在哪里添加?
这是我的.h文件:
@property (strong, nonatomic) CLLocationManager *location;
这是在我的.m文件中:
@synthesize location;
-(void) locationStuff {
//Get location en set MapView
location=[[CLLocationManager alloc]init];
location.delegate=self;
location.desiredAccuracy=kCLLocationAccuracyBest;
location.distanceFilter=kCLDistanceFilterNone;
location.pausesLocationUpdatesAutomatically = NO;
[self startUpdatingLocation];
[mapView setDelegate:self];
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:@"appRunning"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
谁能帮我吗? 再次感谢您,我不明白其他问题的答案。 我真的需要一些简单的解释。
在iOS 8中已更改,您必须使用以下代码请求位置服务。
requestAlwaysAuthorization
用于后台位置
[self.locationManager requestAlwaysAuthorization];
要么
requestWhenInUseAuthorization
仅在应用程序处于活动状态时定位
[self.locationManager requestWhenInUseAuthorization];
如果您没有发出两个请求,iOS将忽略startUpdateLocation请求。
也。 包括NSLocationAlwaysUsageDescription
或NSLocationWhenInUseUsageDescription
键,我认为您已经完成了。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.