Reputation: 1432
My first attempt at building a watchOS app is starting a little rough.
After I select the watchkit extension in the target membership box within the file inspector several errors pop up immediately regarding my CLLocationManager Delegate Class and I am unaware of why this would be the case and not sure how to track down answers for these problems.
Because it is for a watch is there special limitations to what is allowed to be integrated in the shareable code from iOS and watchOS?
Unsure why especially activity type would be unavailable.
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()
}
}
Upvotes: 0
Views: 206
Reputation: 11995
Please, carefully read documentation for CoreLocation and MapKit frameworks. Not all symbols are available on watchOS. For example, MKPolyline
is available on iOS 4.0+, macOS 10.9+, tvOS 9.2+ but not on watchOS.
You also can't use UIViewController
and the entire UIKit
on Apple Watch. Use WatchKit
UI classes, such as WKInterfaceController
.
Good luck in further learning!
Upvotes: 1