2017-11-29 23 views
4

Apple's sample app을 비롯한 모든 곳에서 보았습니다. 그러나 전화에서 코드를 실행하지 않고도 위치를 요청할 수있는 곳을 찾을 수없는 경우 '인터페이스 컨트롤러'에서 사용되는 아래 코드는 '결정되지 않음'상태를 반환합니다. 내 info.plist에 설정된 개인 키 값이 있는지 확인했습니다.Apple 시계의 위치는 페어링 된 전화기에 코드가 없으므로

import Foundation 
import CoreLocation 

class LocationManager: NSObject, CLLocationManagerDelegate { 

    /// Location manager to request authorization and location updates. 
    let manager = CLLocationManager() 

    /// Flag indicating whether the manager is requesting the user's location. 
    var isRequestingLocation = false 

     var workoutLocation: CLLocation? 

    func requestLocation() { 

     guard !isRequestingLocation else { 
      manager.stopUpdatingLocation() 
      isRequestingLocation = false 
      return 
     } 

     let authorizationStatus = CLLocationManager.authorizationStatus() 

     switch authorizationStatus { 
     case .notDetermined: 
      isRequestingLocation = true 
      manager.requestWhenInUseAuthorization() 

     case .authorizedWhenInUse: 
      isRequestingLocation = true 
      manager.requestLocation() 

     case .denied: 
      print("Location Authorization Denied") 
     default: 
      print("Location AUthorization Status Unknown") 
     } 
    } 

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     guard !locations.isEmpty else { return } 

     DispatchQueue.main.async { 
      let lastLocationCoordinate = locations.last!.coordinate 

      print("Lat = \(lastLocationCoordinate.latitude)") 

      print("Long = \(lastLocationCoordinate.longitude)") 

      self.isRequestingLocation = false 

     } 
    } 
} 

홈페이지 앱의 Info.plist

<key>NSLocationAlwaysUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 
    <key>NSLocationUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 
    <key>NSLocationWhenInUseUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 

시계 확장의 Info.plist

<key>NSLocationAlwaysUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 
    <key>NSLocationUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 
    <key>NSLocationWhenInUseUsageDescription</key> 
    <string>We will read your location while performing a workout to create a workout route</string> 

답변

8

사용자는 자신의 아이폰에 자신의 위치에 대한 액세스 권한을 부여 할 수 있습니다. Apple Watch에서는이 작업을 수행 할 수 없습니다. 조사식이 연결된 iPhone이 잠금 해제되어있는 경우 위치 사용 승인을 요청하는 메시지가 전화기에 표시됩니다. iOS에서이 코드를 실행할 필요가 없습니다. App Programming Guide for watchOS: Leveraging iOS Technologies

에서

몇 가지 기술에 대한 해당 권한이 사용자의 아이폰에 동의해야합니다 유의하십시오. 사용자는 핵심 위치와 같은 특정 시스템 기술을 사용할 수있는 권한을 부여해야합니다. WatchKit 확장 프로그램에서 기술 중 하나를 사용하면 사용자의 iPhone에서 적절한 프롬프트가 트리거됩니다. Apple Watch는 또한 사용자에게 을 요청하여 iPhone에 대한 권한 요청을 볼 수 있습니다. 사용자 권한이 필요한 기술에 대한 정보가 인 경우 iOS 용 App Programming Guide의 " 사용자 개인 정보 보호 지원"을 참조하십시오.

+0

나는 아직도 뭔가를 놓치고 있다고 생각합니다. 시계에서'whenInUseStatus'를 요청하지만, 아이폰에서 팝업되는 위치 프롬프트를 요구하는 프롬프트가 없습니까? iPhone에서 코드를 실행할 필요가 없습니까? – GarySabo

+0

아이폰 타겟이 아닌 워치 타겟을 위해'Info.plist' 파일을 올바르게 설정 했습니까? 예, 설명서에도 iOS 코드없이 iPhone에 프롬프트를 표시 할 수 있다고 명시되어 있습니다. –

+0

나는 내 질문에 내 info.plist 값을 추가했다. – GarySabo