2017-03-05 94 views
0

我第一次嘗試構建watchOS應用程序開始有點粗糙。Watchkit擴展時的錯誤

當我在文件檢查器的目標成員資格框中選擇了watchkit擴展後,我的CLLocationManager委託類立即彈出了幾個錯誤,我不知道爲什麼會出現這種情況,不知道如何跟蹤這些答案問題。

因爲它適用於手錶,所以允許在iOS和watchOS的可共享代碼中集成什麼特殊限制?

不確定爲什麼特別是活動類型不可用。

import Foundation 
import CoreLocation 
import MapKit 
import UIKit 

class TrackLocationManagerDelegate: NSObject, CLLocationManagerDelegate { 
     lazy var locationManager: CLLocationManager = { 
      var locationManager   = CLLocationManager() 
     locationManager.delegate  = LocationManagerDelegate.sharedInstance 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 

     // ERROR - activityType unavailable 
     locationManager.activityType = CLActivityType.fitness 

     locationManager.distanceFilter = 10.0 

     return locationManager 
     }() 

    // ERROR - Use of undeclared type MKPolyline 
    fileprivate lazy var polyline = MKPolyline() 

    // ERROR - Use of Undeclared type UIViewController 
    func startUpdatingLocationIfAuthorized(inViewController vc: UIViewController) { 
     guard CLLocationManager.authorizationStatus() == .authorizedWhenInUse else { 
      TrackLocationManagerDelegate.sharedInstance.locationManager.requestWhenInUseAuthorization() 
      return 
     } 

     TrackLocationManagerDelegate.sharedInstance.locationManager.startUpdatingLocation() 
    } 
} 

回答

1

請仔細閱讀文檔CoreLocationMapKit框架。並非所有的符號都可以在watchOS上使用。例如,MKPolyline適用於iOS 4.0+,macOS 10.9+,tvOS 9.2+,但不適用於watchOS。

您也不能在Apple Watch上使用UIViewController和整個UIKit。使用WatchKit UI類,例如WKInterfaceController

祝你好運!

+0

謝謝,通過文檔,它回答了我所有的問題! – lifewithelliott