简体   繁体   English

定位服务在iOS8中不起作用

[英]Location services not working in ios8

I'm struggling for a couple of days now and I'm not able to solve my problem (despite all info here on SO). 我现在已经挣扎了几天,但无法解决我的问题(尽管此处提供了所有信息)。 Sorry for being stupid. 对不起,很抱歉。

In my app location services stopped working in iOS 8. Prior to this version all was OK. 在我的应用中,位置服务在iOS 8中停止工作。在此版本之前,一切正常。 I read here that there must me some keys in de plist file and that they must be set using a external editor. 我在这里阅读到,必须在deplist文件中有一些键,并且必须使用外部编辑器进行设置。

Here it is: 这里是: Plist文件中的键的屏幕快照

But it is still not working. 但是它仍然无法正常工作。 In the simulator, or on my device for that matter, I am not be prompted. 在模拟器中或在我的设备上,不会提示我。

I also understand to add some code to my files. 我也知道在文件中添加一些代码。 What code should I add, where should I add it? 我应该添加什么代码,我应该在哪里添加?

This is my .h file: 这是我的.h文件:

@property (strong, nonatomic) CLLocationManager *location;

This is in my .m file: 这是在我的.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];

} }

Can, please, anyone help me? 谁能帮我吗? Thanks and again sorry that I didn't understand the answers provided to the other questions. 再次感谢您,我不明白其他问题的答案。 I really need some simple explanation. 我真的需要一些简单的解释。

It has changed in iOS 8, You have to request for location servive with following code. 在iOS 8中已更改,您必须使用以下代码请求位置服务。

  • requestAlwaysAuthorization - for background location requestAlwaysAuthorization用于后台位置

    [self.locationManager requestAlwaysAuthorization]; or 要么

  • requestWhenInUseAuthorization -location only when app is active requestWhenInUseAuthorization仅在应用程序处于活动状态时定位

    [self.locationManager requestWhenInUseAuthorization];

If you do not make either of two request , iOS will ignore startUpdateLocation request. 如果您没有发出两个请求,iOS将忽略startUpdateLocation请求。

Also. 也。 Include NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key , Which i see you have already Done. 包括NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription键,我认为您已经完成了。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM