溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS 8.0 CLLocationManager 定位 不響應(yīng)

發(fā)布時間:2020-07-16 15:48:06 來源:網(wǎng)絡(luò) 閱讀:1050 作者:xx541100047 欄目:移動開發(fā)
if ([CLLocationManager locationServicesEnabled]) {
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
        // As of iOS 8, apps must explicitly request location services permissions. INTULocationManager supports both levels, "Always" and "When In Use".
        // INTULocationManager determines which level of permissions to request based on which description key is present in your app's Info.plist
        // If you provide values for both description keys, the more permissive "Always" level is requested.
        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            BOOL hasAlwaysKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil;
            BOOL hasWhenInUseKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil;
            if (hasAlwaysKey) {
                [self.m_locationManager requestAlwaysAuthorization];
            } else if (hasWhenInUseKey) {
                [self.m_locationManager requestWhenInUseAuthorization];
            } else {
                // At least one of the keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription MUST be present in the Info.plist file to use location services on iOS 8+.
                NSAssert(hasAlwaysKey || hasWhenInUseKey, @"To use location services in iOS 8+, your Info.plist must provide a value for either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription.");
            }
        }
#endif /* __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 */
        
        [self.m_locationManager startUpdatingLocation];

上述代碼添加在

[self.m_locationManager startUpdatingLocation];


之前,

除了上述代碼,還需要在info.plist中添加:

<key>NSLocationWhenInUseUsageDescription</key>

<string>這里是授權(quán)彈出框描述文字</string>

    

<key>NSLocationAlwaysUsageDescription</key>

<string>這里是授權(quán)彈出框描述文字</string>


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI