我正在尝试按照WWDC video from apple制作锻炼应用,
遗憾的是,一些方法已经在WatchOS 4中弃用了,我无法使代码工作。每当我点击其中一个按钮开始锻炼时,屏幕变黑,我收到错误Extension[11692:537762] [default] -[SPApplicationDelegate companionConnection:reloadRootInterfaceViewControllersWithNames:initializationContextIDs:pageIndex:verticalPaging:]:1432: Error - interface does not define view controller class 'WorkoutInterfaceController'
第二个视图控制器“WorkoutInterfaceController”位于故事板中并链接到其类。
我的WKInterfaceController类:
class InterfaceController: WKInterfaceController {
@IBOutlet var outdoorBtn: WKInterfaceButton!
@IBOutlet var indoorBtn: WKInterfaceButton!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
@IBAction func didTapOutdoorButton() {
let workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .walking
workoutConfiguration.locationType = .outdoor
// Pass configuration to next interface controller
WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutInterfaceController"], contexts: [workoutConfiguration], orientation: .horizontal, pageIndex: 0)
}
@IBAction func didTapIndoorSaButton() {
let workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .walking
workoutConfiguration.locationType = .indoor
// Pass configuration to next interface controller
WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutInterfaceController"], contexts: [workoutConfiguration], orientation: .horizontal, pageIndex: 0)
}
}
我真的很感激帮助!