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>
나는 아직도 뭔가를 놓치고 있다고 생각합니다. 시계에서'whenInUseStatus'를 요청하지만, 아이폰에서 팝업되는 위치 프롬프트를 요구하는 프롬프트가 없습니까? iPhone에서 코드를 실행할 필요가 없습니까? – GarySabo
아이폰 타겟이 아닌 워치 타겟을 위해'Info.plist' 파일을 올바르게 설정 했습니까? 예, 설명서에도 iOS 코드없이 iPhone에 프롬프트를 표시 할 수 있다고 명시되어 있습니다. –
나는 내 질문에 내 info.plist 값을 추가했다. – GarySabo