Nice programing

iOS 8에서 작동하지 않는 위치 서비스

nicepro 2020. 10. 2. 23:18
반응형

iOS 8에서 작동하지 않는 위치 서비스


iOS 7에서 제대로 작동했던 내 앱이 iOS 8 SDK에서 작동하지 않습니다.

CLLocationManager위치를 반환하지 않으며 설정 -> 위치 서비스 에도 내 앱이 표시되지 않습니다 . 문제에 대해 Google 검색을 수행했지만 아무 것도 나타나지 않았습니다. 무엇이 잘못 되었을까요?


나는 결국 내 자신의 문제를 해결했습니다.

분명히 iOS 8 SDK에서는 위치 업데이트를 시작하기 전에 ( requestAlwaysAuthorization백그라운드 위치의 경우) 또는 requestWhenInUseAuthorization(포 그라운드에서만 위치) 호출 CLLocationManager이 필요합니다.

또한있을 필요가 NSLocationAlwaysUsageDescription또는 NSLocationWhenInUseUsageDescription핵심 Info.plist메시지와 함께 프롬프트에 표시 할 수 있습니다. 이것들을 추가하면 내 문제가 해결되었습니다.

여기에 이미지 설명 입력

다른 사람에게 도움이되기를 바랍니다.

편집 : 더 광범위한 정보를 보려면 Core-Location-Manager-Changes-in-ios-8을 참조하십시오.


나는 같은 문제로 머리카락을 뽑았다. Xcode는 오류를 제공합니다.

MapKit위치 인증을 요청하지 않고 위치 업데이트 를 시작하려고합니다 . -[CLLocationManager requestWhenInUseAuthorization]또는 -[CLLocationManager requestAlwaysAuthorization]먼저 전화해야합니다 .

그러나 위의 방법 중 하나를 구현하더라도 info.plist에 NSLocationAlwaysUsageDescription또는 에 대한 항목이 없으면 사용자에게 메시지를 표시하지 않습니다 NSLocationWhenInUseUsageDescription.

info.plist에 다음 줄을 추가합니다. 여기서 문자열 값은 사용자 위치에 액세스해야하는 이유를 나타냅니다.

<key>NSLocationWhenInUseUsageDescription</key>
<string>This application requires location services to work</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>This application requires location services to work</string>

Xcode 5에서이 프로젝트를 시작한 이후로 이러한 항목이 누락되었을 수 있다고 생각합니다. Xcode 6이 이러한 키에 대한 기본 항목을 추가 할 수 있지만 확인하지 않은 것 같습니다.

이 두 설정에 대한 자세한 정보는 여기 에서 찾을 수 있습니다.


이것이 iOS 7과 역 호환되는지 확인하려면 사용자가 iOS 8 또는 iOS 7을 실행 중인지 확인해야합니다. 예 :

#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

//In ViewDidLoad
if(IS_OS_8_OR_LATER) {
   [self.locationManager requestAlwaysAuthorization];
}

[self.locationManager startUpdatingLocation];

- (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


}

그리고 info.plist 파일에 여기에 이미지 설명 입력


Apple 문서에 따르면 :

iOS 8부터 앱의 Info.plist 파일에 NSLocationWhenInUseUsageDescription또는 NSLocationAlwaysUsageDescription키 값이 있어야합니다. 그런 다음 전화를 [self.myLocationManager requestWhenInUseAuthorization]하거나 [self.myLocationManager requestAlwaysAuthorization]필요에 따라 위치 업데이트를 등록하기 전에 사용자에게 권한을 요청 해야합니다. Info.plist에 입력 한 문자열이 다음 대화 상자에 표시됩니다.

사용자가 권한을 부여하면 평소와 같은 업무입니다. 권한을 거부하면 대리인에게 위치 업데이트 알림이 표시되지 않습니다.


- (void)viewDidLoad
{

    [super viewDidLoad];
    self.locationManager = [[CLLocationManager alloc] init];

    self.locationManager.delegate = self;
    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){
        NSUInteger code = [CLLocationManager authorizationStatus];
        if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
            // choose one request according to your business.
            if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){
                [self.locationManager requestAlwaysAuthorization];
            } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
                [self.locationManager  requestWhenInUseAuthorization];
            } else {
                NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
            }
        }
    }
    [self.locationManager startUpdatingLocation];
}

>  #pragma mark - CLLocationManagerDelegate

    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        NSLog(@"didFailWithError: %@", error);
        UIAlertView *errorAlert = [[UIAlertView alloc]
                                   initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
    }

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        NSLog(@"didUpdateToLocation: %@", newLocation);
        CLLocation *currentLocation = newLocation;

        if (currentLocation != nil) {
            longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
            latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
        }
    }

iOS 8에서 위치를 작동하려면 두 가지 추가 작업을 수행해야합니다. Info.plist에 키를 추가하고 시작을 요청하는 위치 관리자에게 인증을 요청합니다. 새 위치 인증을위한 두 개의 Info.plist 키가 있습니다. 이 키 중 하나 또는 모두가 필요합니다. 키가없는 경우 startUpdatingLocation을 호출 할 수 있지만 위치 관리자는 실제로 시작되지 않습니다. 대리자에게도 실패 메시지를 보내지 않습니다 (시작되지 않았으므로 실패 할 수 없습니다). 키 중 하나 또는 둘 모두를 추가했지만 명시 적으로 인증을 요청하는 것을 잊은 경우에도 실패합니다. 따라서 가장 먼저해야 할 일은 Info.plist 파일에 다음 키 중 하나 또는 둘 다를 추가하는 것입니다.

  • NSLocationWhenInUseUsageDescription
  • NSLocationAlwaysUsageDescription

이 두 키는 모두 문자열을받습니다.

위치 서비스가 필요한 이유에 대한 설명입니다. iOS 7에서와 같이 InfoPlist.strings 파일에서 현지화 할 수있는 "현재 위치를 찾으려면 위치가 필요합니다."와 같은 문자열을 입력 할 수 있습니다.

여기에 이미지 설명 입력


Xcode 5에서 컴파일 할 수있는 내 솔루션 :

#ifdef __IPHONE_8_0
    NSUInteger code = [CLLocationManager authorizationStatus];
    if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
        // choose one request according to your business.
        if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){
            [self.locationManager requestAlwaysAuthorization];
        } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
            [self.locationManager  requestWhenInUseAuthorization];
        } else {
            NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
        }
    }
#endif
    [self.locationManager startUpdatingLocation];

위치를 묻는 이전 코드는 iOS 8에서 작동하지 않습니다. 위치 인증을 위해 다음 방법을 시도 할 수 있습니다.

- (void)requestAlwaysAuthorization
{
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

    // If the status is denied or only granted for when in use, display an alert
    if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status ==        kCLAuthorizationStatusDenied) {
        NSString *title;
        title = (status == kCLAuthorizationStatusDenied) ? @"Location services are off" :   @"Background location is not enabled";
        NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings";

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                            message:message
                                                           delegate:self
                                                  cancelButtonTitle:@"Cancel"
                                                  otherButtonTitles:@"Settings", nil];
        [alertView show];
    }
    // The user has not enabled any location services. Request background authorization.
    else if (status == kCLAuthorizationStatusNotDetermined) {
        [self.locationManager requestAlwaysAuthorization];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        // Send the user to the Settings for this app
        NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:settingsURL];
    }
}

iOS 8에서 위치를 작동하려면 두 가지 추가 작업을 수행해야합니다. Info.plist에 키를 추가하고 시작을 요청하는 위치 관리자에게 인증을 요청합니다.

info.plist :

<key>NSLocationUsageDescription</key>
<string>I need location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>I need location</string>

이것을 코드에 추가하십시오.

if (IS_OS_8_OR_LATER)
{
    [locationmanager requestWhenInUseAuthorization];

    [locationmanager requestAlwaysAuthorization];
}

Swift 개발자를위한 일반적인 오류 :

먼저 NSLocationWhenInUseUsageDescription또는 에 대한 plist에 값을 추가했는지 확인하십시오 NSLocationAlwaysUsageDescription.

당신이 경우 여전히 윈도우가 인증을 요청하는 팝업 표시되지 않는, 당신은 라인을 가하고 있는지 살펴 var locationManager = CLLocationManager()보기 컨트롤러의에서 viewDidLoad방법. 그렇게 locationManager.requestWhenInUseAuthorization()하면를 호출 해도 아무 것도 표시되지 않습니다. 이는 viewDidLoad가 실행 된 후 locationManager 변수가 할당 해제 (삭제)되기 때문입니다.

해결책은 var locationManager = CLLocationManager()클래스 메서드의 맨 위에 줄을 찾는 것입니다.


이전 [locationManager startUpdatingLocation];에 iOS8 위치 서비스 요청을 추가하십시오.

if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
    [locationManager requestAlwaysAuthorization];

편집 앱 Info.plist과 추가 키 NSLocationAlwaysUsageDescription사용자에게 표시되는 문자열 값 (예를 들어 We do our best to preserve your battery life.)

앱이 열려있는 동안에 만 앱에 위치 서비스가 필요한 경우 다음을 교체합니다.

requestAlwaysAuthorizationrequestWhenInUseAuthorization

NSLocationAlwaysUsageDescription와 함께 NSLocationWhenInUseUsageDescription.


iOS 8로 업그레이드 된 앱을 작업 중이었고 위치 서비스가 작동을 멈췄습니다. 디버그 영역에서 다음과 같이 오류가 발생합니다.

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

나는 최소한의 침입 절차를 수행했습니다. 먼저 NSLocationAlwaysUsageDescriptioninfo.plist 항목을 추가 하십시오.

여기에 이미지 설명 입력

이 키의 값을 입력하지 않았습니다. 이것은 여전히 ​​작동하며 이것이 사내 앱이기 때문에 걱정하지 않습니다. 또한 이미 위치 서비스 이용을 요청하는 타이틀이있어서 중복되는 것을하고 싶지 않았습니다.

다음으로 iOS 8에 대한 조건부를 만들었습니다.

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
    [_locationManager requestAlwaysAuthorization];
}

이 후 locationManager:didChangeAuthorizationStatus:메서드는 호출됩니다.

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:  (CLAuthorizationStatus)status
{
    [self gotoCurrenLocation];
}

이제 모든 것이 잘 작동합니다. 항상 그렇듯이 문서를 확인하십시오 .


이전 버전과의 호환성이있는 솔루션 :

SEL requestSelector = NSSelectorFromString(@"requestWhenInUseAuthorization");
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
    [self.locationManager respondsToSelector:requestSelector]) {
    [self.locationManager performSelector:requestSelector withObject:NULL];
} else {
    [self.locationManager startUpdatingLocation];
}

Info.plist에서 NSLocationWhenInUseUsageDescription 키 설정


Xcode 경고를 생성하지 않는 이전 버전과의 호환성이있는 솔루션 :

SEL requestSelector = NSSelectorFromString(@"requestWhenInUseAuthorization");
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
  [self.locationManager respondsToSelector:requestSelector]) {
((void (*)(id, SEL))[self.locationManager methodForSelector:requestSelector])(self.locationManager, requestSelector);
  [self.locationManager startUpdatingLocation];
} else {
  [self.locationManager startUpdatingLocation];
}

설정 NSLocationWhenInUseUsageDescription당신의 키 Info.plist.

아이폰 OS 버전 11.0 이상에 대한 설정 : NSLocationAlwaysAndWhenInUseUsageDescription당신의 키 Info.plist. 다른 2 개의 키와 함께.


이것은 iOS 8의 문제입니다 코드에 이것을 추가하십시오

if (IS_OS_8_OR_LATER)
{
    [locationmanager requestWhenInUseAuthorization];

    [locationmanager requestAlwaysAuthorization];
}

그리고 info.plist :

 <key>NSLocationUsageDescription</key>
 <string>I need location</string>
 <key>NSLocationAlwaysUsageDescription</key>
 <string>I need location</string>
 <key>NSLocationWhenInUseUsageDescription</key>
 <string>I need location</string>

iOS 8에서 사용자 위치에 액세스하려면 다음을 추가해야합니다.

NSLocationAlwaysUsageDescription in the Info.plist 

사용자에게 현재 위치를 가져올 수있는 권한을 요청합니다.


Objective-C 절차 아래 지침을 따르십시오.

iOS-11의 경우 iOS 11의 경우 답변 : iOS 11 위치 액세스

plist에 두 개의 키를 추가하고 아래 이미지와 같이 메시지를 제공해야합니다.

 1. NSLocationAlwaysAndWhenInUseUsageDescription 
 2. NSLocationWhenInUseUsageDescription
 3. NSLocationAlwaysUsageDescription

여기에 이미지 설명 입력 iOS-10 이하 :

NSLocationWhenInUseUsageDescription

여기에 이미지 설명 입력

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
    [locationManager requestWhenInUseAuthorization];
}else{
    [locationManager startUpdatingLocation];
} 

위임 방법

#pragma mark - Lolcation Update 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status) {
        case kCLAuthorizationStatusNotDetermined:
        case kCLAuthorizationStatusRestricted:
        case kCLAuthorizationStatusDenied:
        {
            // do some error handling
        }
            break;
        default:{
            [locationManager startUpdatingLocation];
        }
            break;
    }
}
- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];
    userLatitude =  [NSString stringWithFormat:@"%f", location.coordinate.latitude] ;
    userLongitude =  [NSString stringWithFormat:@"%f",location.coordinate.longitude];
    [locationManager stopUpdatingLocation];
}

신속한 절차

아래 지침을 따르십시오.

iOS-11의 경우 iOS 11의 경우 답변 : iOS 11 위치 액세스

plist에 두 개의 키를 추가하고 아래 이미지와 같이 메시지를 제공해야합니다.

 1. NSLocationAlwaysAndWhenInUseUsageDescription 
 2. NSLocationWhenInUseUsageDescription
 3. NSLocationAlwaysUsageDescription

여기에 이미지 설명 입력 iOS-10 이하 :

여기에 이미지 설명 입력

import CoreLocation
class ViewController: UIViewController ,CLLocationManagerDelegate {
var locationManager = CLLocationManager()

//MARK- Update Location 
func updateMyLocation(){
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
    if locationManager.respondsToSelector(#selector(CLLocationManager.requestWhenInUseAuthorization)){
       locationManager.requestWhenInUseAuthorization()
    }
    else{
        locationManager.startUpdatingLocation()
    }
}

위임 방법

//MARK: Location Update
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    NSLog("Error to update location :%@",error)
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    switch status {
    case .NotDetermined: break
    case .Restricted: break
    case .Denied:
            NSLog("do some error handling")
        break
    default:
        locationManager.startUpdatingLocation()
    }
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
     let location = locations.last! as CLLocation
    var latitude = location.coordinate.latitude
    var longitude = location.coordinate.longitude

}

사용하는 사람들을 위해 자 마린을 , 나는 키를 추가했다 NSLocationWhenInUseUsageDescription단지 - 그것은 하나 자 마린 5.5.3 빌드 6 엑스 코드 6.1의 드롭 다운에서 사용할 수없는 수동으로부터의 Info.plist에 NSLocationUsageDescription목록에, 그리고 그이 (가) 발생 CLLocationManager에 계속 조용히 실패합니다.


        // ** Don't forget to add NSLocationWhenInUseUsageDescription in MyApp-Info.plist and give it a string

        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
        if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [self.locationManager requestWhenInUseAuthorization];
        }
        [self.locationManager startUpdatingLocation];


    // Location Manager Delegate Methods    
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        NSLog(@"%@", [locations lastObject]);

}

하나 이상의 Info.plist 파일을 가지고있는 여러분 모두를위한 작은 도우미 ...

find . -name Info.plist | xargs -I {} /usr/libexec/PlistBuddy -c 'Add NSLocationWhenInUseUsageDescription string' {} 

현재 디렉터리 (및 하위 폴더)의 모든 Info.plist 파일에 필요한 태그를 추가합니다.

또 하나는 :

find . -name Info.plist | xargs -I {} /usr/libexec/PlistBuddy -c 'Set NSLocationWhenInUseUsageDescription $YOURDESCRIPTION' {} 

모든 파일에 설명을 추가합니다.


이러한 업데이트를 위해 Cocoa Keys 정보를 항상 손끝에 보관하십시오 . 링크는 다음과 같습니다.

https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW26

즐겨.


iOS9에서 비슷한 오류가 발생합니다 (Xcode 7 및 Swift 2에서 작동) : 위치 인증을 요청하지 않고 MapKit 위치 업데이트를 시작하려고합니다. 먼저-[CLLocationManager requestWhenInUseAuthorization] 또는-[CLLocationManager requestAlwaysAuthorization]을 호출해야합니다. 나는 튜토리얼을 따르고 있었지만 튜터는 iOS8과 Swift 1.2를 사용하고있었습니다. Xcode 7과 Swift 2에 몇 가지 변경 사항이 있습니다.이 코드를 찾았고 잘 작동합니다 (누군가 도움이 필요한 경우).

import UIKit
import MapKit
import CoreLocation

class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    // MARK: Properties
    @IBOutlet weak var mapView: MKMapView!

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.startUpdatingLocation()
        self.mapView.showsUserLocation = true

    }

    // MARK: - Location Delegate Methods

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last
        let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
        self.mapView.setRegion(region, animated: true)
    }

    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print("Errors: " + error.localizedDescription)
    }
}

마지막으로 info.plist에 넣습니다. 정보 속성 목록 : NSLocationWhenInUseUsageDescription 값 : 앱에는 직원을위한 위치 서버가 필요합니다.


iOS에서 사용자 위치에 액세스하기 위해. 두 개의 키를 추가해야합니다.

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

Info.plist 파일에.

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Because I want to know where you are!</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Want to know where you are!</string>

아래 이미지를 참조하십시오.

Info.plist 이미지


  1. 각 타겟에서 GPS를 사용하도록 요청하는 문자열과 함께 NSLocationWhenInUseUsageDescription또는 NSLocationAlwaysUsageDescription(백그라운드 GPS 사용)을 추가합니다 info.plist.

  2. 다음을 실행하여 권한을 요청하십시오.

    [self initLocationManager : locationManager];

어디에 initLocationManager:

// asks for GPS authorization on iOS 8
-(void) initLocationManager:(CLLocationManager *) locationManager{

    locationManager = [[CLLocationManager alloc]init];

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

info.plist각 대상 에 대한 키가 각각 에 없으면 앱은 사용자에게 묻지 않습니다. if아이폰 OS 7과의 호환성을 제공하며, respondsToSelector:방법은 아이폰 OS 7과 8의 문제를 해결하기보다는 미래의 호환성을 보장합니다.


나에게 문제는 CLLocationManagerDelegate모든 대리자 메서드가 호출되지 못하게하는 개인 클래스 라는 것입니다. 매우 흔한 상황은 아니지만 t가 누구에게나 도움이 될 경우 언급 할 것이라고 생각했습니다.


나는에서 그 키를 추가 InfoPlist.strings아이폰 OS 8.4, 아이 패드 미니 2는 너무 작동합니다. NSLocationWhenInUseUsageDescription에서 , 같은 키를 설정하지 않았습니다 Info.plist.


InfoPlist.strings :

"NSLocationWhenInUseUsageDescription" = "I need GPS information....";

이 스레드에 대한 자료는 ,이 말 as in iOS 7의 InfoPlist.strings에서 지역화 할 수 있습니다. 내 테스트에서 이러한 키는 파일에서 직접 구성 할 수 있습니다 InfoPlist.strings.

따라서 가장 먼저해야 할 일은 Info.plist 파일에> 다음 키 중 하나 또는 둘 다를 추가하는 것입니다.

  • NSLocationWhenInUseUsageDescription
  • NSLocationAlwaysUsageDescription

두 키 모두 위치 서비스가 필요한 이유를 설명하는 문자열을 사용합니다. iOS 7 에서와 같이 InfoPlist.strings 파일에서 현지화 할 수있는 "현재 위치를 찾으려면 위치가 필요합니다."와 같은 문자열을 입력 할 수 있습니다.


최신 정보:

@IOS의 방법이 더 낫다고 생각 합니다. Info.plist빈 값으로에 키를 추가 하고에 현지화 된 문자열을 추가합니다 InfoPlist.strings.

참고 URL : https://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8

반응형