2017-03-05 111 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