有没有办法让ExtensionDelegate具有多个watchOSExtensions? 我的目标是只有几种方法可以使用watcho 3.0,还有一些方法可以使用watchos 2.0。
根据Xcode 8.6 Beta,要求如下:
错误:
协议' WKExtensionDelegate'需要处理'可在watchOS应用程序扩展2.2.0和更新
上使用import WatchKit
import HealthKit
@available(watchOSApplicationExtension 2.2.0, *)
class ExtensionDelegate: NSObject, WKExtensionDelegate {
}//eoc
@available(watchOSApplicationExtension 3.0, *)
extension ExtensionDelegate
{
@objc(handleWorkoutConfiguration:)
func handle(_ workoutConfiguration: HKWorkoutConfiguration) {
}
}
答案 0 :(得分:0)
似乎Xcode beta在发出错误时脑部冻结了。 关闭Xcode beta并再次打开它,一切似乎都很好。我将代码更新到下面,它运行成功。
import WatchKit
import HealthKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
}
func applicationDidBecomeActive() {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillResignActive() {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, etc.
}
@available(watchOSApplicationExtension 3.0, *)
func handle( workoutConfiguration: HKWorkoutConfiguration)
{
}//eom
}//eoc
答案 1 :(得分:0)
在watchOS 3.0 GM Seed中,我能找到的唯一解决方法是添加WK_AVAILABLE_WATCHOS_ONLY(3.0);到WKExtensionDelegate头文件中句柄(_ :)方法的声明。 (显然是临时修复;我认为Apple会在最终版本中将其添加到标题中。)