2014年9月30日 星期二

iOS 8 Location 定位 失效

一,先在Info.plist加入這二個Key(value是string,你可以不加,也可以加上Location is required to find out where you are之類的文字
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription

二,在啟用location update之前加入這段,來要求權限
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
        if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
//要求權限:前景背景都允許使用定位
            [_locationManager requestAlwaysAuthorization];
        }
        if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
//要求權限:只有在前景允許使用定位
            [_locationManager requestWhenInUseAuthorization];

        }

沒有留言:

張貼留言