1

watchOSシミュレータの位置をシミュレートする方法はありますか?要求WatchOSシミュレータでの位置検出が失敗しました

- (void) requestLocation { 
    locationManager = [CLLocationManager new]; 

    locationManager.delegate = self; 

    [locationManager requestWhenInUseAuthorization]; 
    [locationManager requestLocation]; 
} 

を使用して

私は常にエラーをキャッチ:エラーが時計シミュレータにおける位置検出作業を行うために NSError * domain: @"kCLErrorDomain" - code: 0 0x7a867970

+0

http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 –

+0

は、恐れ入りますが、それは動作しません。さらに、watchOSシミュレータに関する情報はありません。 – Vyacheslav

答えて

1

ある

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
     // Error here if no location can be found 
} 

、あなたが必要とされていますiPhoneのシミュレータの位置を設定することもできます。私はあなたがiPhoneシミュレータで

  1. セット場所としての手順に従うことを提案する、(デバッグ - >所在地 - >カスタムの場所)時計simlautorで
  2. セット場所、(デバッグ - >所在地 - >カスタム場所)
  3. 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)") 
} 
} 
+0

私は多くの時間をテストしました。それは動作しません – Vyacheslav

+0

iPhone/iPadシミュレータが動作します。しかし、watchOSはありません。 – Vyacheslav

+0

上記の手順を使用して時計アプリの位置をシミュレートすることに成功しました。 – vkhemnar

関連する問題