在Apple开发者文档章节“ There and Back Again ”中,手表应用程序的App是这样写的:
@main
struct MyWatchApp: App {
@WKExtensionDelegateAdaptor(ExtensionDelegate.self) var extensionDelegate
@SceneBuilder var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我在 var 声明中收到紫色运行时警告,上面写着
@WKExtensionDelegateAdaptor 只能在基于扩展的进程中使用
Xcode 中一定有某些东西明确将 App 结构定义为“基于扩展”,但我找不到它!
编辑:更多说明...我正在尝试处理运行 HealthKit 方法startWatchApp(with:completion:)后调用的特殊方法
手表扩展的特殊方法是funchandle(_workoutConfiguration: HKWorkoutConfiguration)
我似乎找不到一种方法将此函数链接到App手表应用程序的新结构上。
当源是Apple Watch时,Health App会显示Watch图标.
我只想获得Health App用来确定源类型的相同信息.HKSource似乎没有提供.
我的手表应用程序可以轻松地从HealthKit的HKAnchoredObjectQuery中的新updateHandler中读取新的心率数据.
麻烦的是,手机应用程序观察到的健康商店似乎与手表不同步.
暂停应用程序并恢复它有时会促使HealthKit执行(似乎是)手表的健康商店和手机商店之间的同步.我不知道为什么会这样.
我需要的是一些在设备之间不断重新同步健康商店的方法.如果我只是通过WatchConnectivity将最新的心率数据从手表发送到手机应用程序,那么我确实可以获得显示所需的数据,但是如果我将这些数据提交到商店,我会在手表的时候获得重复数据.商店DOES同步.
这是一个主要问题,因为它将HealthKit作为可读的单一位置来读取和写入健康数据.
编辑:Apple Bug Report雷达https://openradar.appspot.com/radar?id=5033927626457088
我有一个应用程序,应该在后台获取对象并使用它们的位置数据为它们生成地图快照。我自然尝试了 MKMapSnapshotter。
事实证明(在对黑色地图快照感到困惑数周之后)这个工具似乎只有在从主线程调用时才起作用,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithQueue:dispatch_get_main_queue() completionHandler:^(MKMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
//Use image here. Image would be completely black if not for the first line of code specifying main thread.
}];
});
Run Code Online (Sandbox Code Playgroud)
这是一个框架错误吗?
问题:这只在我的应用程序位于前台时运行。
ios ×3
healthkit ×2
apple-watch ×1
ios9 ×1
mapkit ×1
objective-c ×1
watchkit ×1
watchos ×1
xcode ×1