【问题标题】:Location services not working in ios8定位服务在 ios8 中不起作用
【发布时间】:2014-09-20 13:51:13
【问题描述】:

我现在苦苦挣扎了几天,但我无法解决我的问题(尽管这里有关于 SO 的所有信息)。对不起,我很愚蠢。

在我的应用中,位置服务在 iOS 8 中停止工作。在此版本之前,一切正常。 我在这里读到 de plist 文件中必须有一些键,并且必须使用外部编辑器设置它们。

这里是:

但它仍然无法正常工作。在模拟器中,或者在我的设备上,我不会被提示。

我也知道在我的文件中添加一些代码。 我应该添加什么代码,我应该在哪里添加?

这是我的 .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 ios8 cllocationmanager


    【解决方案1】:

    在 iOS 8 中发生了变化,您必须使用以下代码请求位置服务。

    • requestAlwaysAuthorization - 用于后台定位

      [self.locationManager requestAlwaysAuthorization];

    • requestWhenInUseAuthorization-location 仅在应用处于活动状态时

      [self.locationManager requestWhenInUseAuthorization];

    如果您没有提出两个请求中的任何一个,iOS 将忽略 startUpdateLocation 请求。

    还有。 包括 NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription 键,我看到你已经完成了。

    希望这会有所帮助。

    【讨论】:

    • 部分帮助。我把代码 [self.location requestAlwaysAuthorization];在我看来DidLoad。有时会弹出对话框,有时不会。钥匙仍然在同一个地方。有时它会提供一个位置,我的应用程序可以运行,有时没有可见的位置,显然应用程序无法运行。有什么建议吗?
    猜你喜欢
    • 2014-09-30
    • 2017-11-09
    • 2014-10-09
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    相关资源
    最近更新 更多