ある
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
// Error here if no location can be found
}
、あなたが必要とされていますiPhoneのシミュレータの位置を設定することもできます。私はあなたがiPhoneシミュレータで
- セット場所としての手順に従うことを提案する、(デバッグ - >所在地 - >カスタムの場所)時計simlautorで
- セット場所、(デバッグ - >所在地 - >カスタム場所)
- watchkit appを実行すると、iPhoneシミュレータ内の場所がNoneにリセットされることがあります。したがって、あなたがその場所にアクセスする前に時計延長コードの前にブレークポイントを置いてください。チェック・ロケーションは、両方のシミュレータで設定されています。
これが役に立ちます。迅速で
サンプルコード、
class LocationManager: NSObject, CLLocationManagerDelegate
{
static let sharedInstance = VCLocationManager()
private var locationManager : CLLocationManager?
private override init()
{
}
func initLocationMonitoring()
{
//didChangeAuthorizationStatus is called as soon as CLLocationManager instance is created.
//Thus dont check authorization status here because it will be always handled.
if locationManager == nil
{
locationManager = CLLocationManager()
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.delegate = self
}
else
{
getCurrentLocation()
}
}
func getCurrentLocation()
{
let authorizationStatus = CLLocationManager.authorizationStatus()
handleLocationServicesAuthorizationStatus(authorizationStatus)
}
func handleLocationServicesAuthorizationStatus(status: CLAuthorizationStatus)
{
switch status
{
case .NotDetermined:
handleLocationServicesStateNotDetermined()
case .Restricted, .Denied:
handleLocationServicesStateUnavailable()
case .AuthorizedAlways, .AuthorizedWhenInUse:
handleLocationServicesStateAvailable()
}
}
func handleLocationServicesStateNotDetermined()
{
locationManager?.requestWhenInUseAuthorization()
}
func handleLocationServicesStateUnavailable()
{
//Ask user to change the settings through a pop up.
}
func handleLocationServicesStateAvailable()
{
locationManager?.requestLocation()
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
handleLocationServicesAuthorizationStatus(status)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
guard let mostRecentLocation = locations.last else { return }
print(mostRecentLocation)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("CL failed: \(error)")
}
}
http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 –
は、恐れ入りますが、それは動作しません。さらに、watchOSシミュレータに関する情報はありません。 – Vyacheslav