CLLocationManager Delegate methods are not getting called -- ios8 later

解决方法:

1、http://stackoverflow.com/questions/20072231/cllocationmanager-delegate-methods-are-not-getting-called

Also know that CoreLocation permissions have changed with iOS 8. If you don't request the new permissions authorizations, CoreLocation doesn't do anything. It fails quietly because the delegate methods are never called.

I realize this question was asked in 2013, but if you are having a similar problem with the delegate methods not getting called, this article is extremely helpful:

http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/   -- 更加详细的说明

While the article is very detailed and long, the actual code fix can be as minor as this:

if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [locationManager requestWhenInUseAuthorization];
}

And you have to add a value to info.plist, which is the message to display in the permissions alert. See screen grab.

Screen grab of new entry in info.plist

Key: NSLocationWhenInUseUsageDescription

Value: Location is required to find out where you are (You can change that to whatever you want)

share improve this answer
 
1 
Thank you very much for giving the link. I don't know why people won't give upvote for this answer, due to no vote I was ignoring this answer..... Thanx again –  sandy  May 26 '15 at 12:13 
1 
Thanks. Saved my time –  iOSDev  Nov 27 '15 at 9:47

2、http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8/24063578#24063578

2.1
943
down vote accepted

I ended up solving my own problem.

Apparently in iOS 8 SDK, requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground) call on CLLocationManager is needed before starting location updates.

There also needs to be NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt. Adding these solved my problem.

Hope it helps someone else.

EDIT: For more extensive information, have a look at: Core-Location-Manager-Changes-in-ios-8

2.2

- (void)startLocationManager
{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];
    [locationManager requestWhenInUseAuthorization]; // Add This Line


}

And to your info.plist File enter image description here


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值