0

은의 Info.plist응용 프로그램이 위치 서비스 권한을 요구하지 않습니다. WhenInInse when installation? 내 app.I에서 구글 맵을 사용하고

개인 정보 취급 방침 및 청소년 보호 정책이 설정 - 위치 할 때 사용 사용법 설명에

내 코드 (홈 화면)에서 나도 같이 확인 해요 :

if (CLLocationManager.locationServicesEnabled()) 
    { 
     locationManager = CLLocationManager() 
     locationManager.delegate = self 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     locationManager.requestAlwaysAuthorization() 
     locationManager.startUpdatingLocation() 
    } else{ 
     let alertController = UIAlertController(title: "Oops !!" , message: "Location service seems to be disabled. Please enable from Settings -> Privacy ->LocationService.", preferredStyle: .Alert) 
     let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil) 
     alertController.addAction(defaultAction) 
     self.presentViewController(alertController, animated: true, completion: nil) 
    } 

처음으로 앱을 설치할 때 허가 여부를 묻지 않습니다. 어떤 도움이라도 appriciate 것입니다.

+0

당신이 운전 중인지 아닌지 여부를 감지 할 수 있도록 귀하의 위치에 대한 액세스가 필요합니다. .plist 파일의 ? –

+0

귀하의 appdelegates.swift 파일에이 코드를 설정하십시오. –

+0

@HimanshuMoradiya AppDelagate에 추가 할 코드는 무엇입니까 ?? –

답변

0
import CoreLocation 
class AppDelegate: CLLocationManagerDelegate{ 

var locationManager: CLLocationManager! 
var currentCoordinate: CLLocationCoordinate2D? 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     self.setupLocationManager() 
     return true 
} 

func setupLocationManager(){ 

     locationManager = CLLocationManager() 
     locationManager?.delegate = self 
     self.locationManager?.requestAlwaysAuthorization() 
     locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters 
     locationManager?.startUpdatingLocation() 
    } 

// Below method will provide you current location. 
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

    if currentCoordinate == nil { 
     currentCoordinate = locations.last?.coordinate 
     locationManager?.stopMonitoringSignificantLocationChanges() 
     let locationValue:CLLocationCoordinate2D = manager.location!.coordinate 

     print("locations = \(locationValue)") 
     //currentCoordinate use this location Coordinate in your whole app. 
     locationManager?.stopUpdatingLocation() 
    } 
} 

// Below Mehtod will print error if not able to update location. 
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 
    print("Error") 
} 

내 대답에 따른 질문이 있으면 알려주십시오.

+0

완벽하게 작동합니다. –

+0

@AnushkaMadushan 이것이 왜 작동하지 않을까요? –

+0

죄송합니다. 어떻게 변경할 수 있습니까? –

2

사용자가 응용 프로그램을 사용할 때 (예 : 포 그라운드에있을 때) 위치에 액세스하기 위해 Info.plist 키를 설정했지만 코드에서 응용 프로그램이 실행될 때마다 (즉, 항상) 권한을 요청합니다. .

원하는 것을 결정해야합니다. 항상 사용자의 위치에 액세스하려면 Info.plist 키를 변경하십시오. 응용 프로그램이 포 그라운드에있을 때 사용자의 위치에 액세스하려면 권한 요청을 requestWhenInUseAuthorization()으로 변경하십시오. 아이폰 OS 10에서

0

는 이후 우리는 단지 enter image description here

을 다음과 같이 .plist 파일의 위치 권한을 부여하고 단지 앱의 위치 서비스를 사용하거나 사용하지 settings.Settings에 확인해야합니다 -> 앱 이름 -> 위치 허용 접속하다. 절대로 선택해서는 안됩니다.

기기에서 앱을 삭제하고 앱을 다시 설치하면 위치 권한이 필요합니다. !