因此,WatchOS 2 支持核心运动框架,并允许活动的 WatchKit 应用程序访问来自 Apple Watch 加速计的数据。我想访问这些数据,但是是在 iPhone 上。除了在手表上打开一个应用程序来收集数据并通过手表连接将其传输回手机之外,还有其他方法可以做到这一点吗?
在 Healthkit 中,手表收集的所有数据都会同步回手机,这意味着我的 iPhone 应用程序可以通过 HKSampleQuery 直接获取数据。我想知道 Healthkit 中的“Active Energy”记录是否只是手表核心运动加速度计数据的汇总,但我不确定。
我曾考虑过使用手表连接和 SendMessage 将手表从 iPhone 上唤醒并获取数据,但我读到这是不可能的。我可以从手表上唤醒 iPhone,但反之则不行。
我看过 WWDC 2015 视频,包括“核心运动的新增功能”。它显示您可以在手表上获取核心运动数据,但无法在iPhone上获取手表核心运动数据。
有什么建议么?谢谢
首先,我知道可以选择使用 SwiftUI 列表等来获得类似的效果。但我需要 UICollectionView 的自动滚动功能,所以我真的很想实现一个“老派”版本。我什至不想要理想的构图布局版本。
我当前的代码如下所示:
import SwiftUI
struct CollectionView: UIViewControllerRepresentable {
private var isActive: Binding<Bool>
private let viewController = UIViewController()
private let collectionController: UICollectionView
init(_ isActive: Binding<Bool>) {
self.isActive = isActive
self.collectionController = UICollectionView(frame: CGRect(x: 0, y: 0, width: 100, height: 200), collectionViewLayout: UICollectionViewFlowLayout())
}
func makeUIViewController(context: UIViewControllerRepresentableContext<CollectionView>) -> UIViewController {
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<CollectionView>) {
if self.isActive.wrappedValue && collectionController.delegate == nil { // to not show twice
collectionController.delegate = context.coordinator
collectionController.dataSource = context.coordinator …Run Code Online (Sandbox Code Playgroud) 我正在尽可能使用 SwiftUI 创建一个新的 iOS 应用程序。但是,我希望能够生成包含一些数据的 PDF。在没有 swiftUI 的类似项目中,我可以做到这一点
let docController = UIDocumentInteractionController.init(url: "PATH_TO_FILE")
docController.delegate = self
self.dismiss(animated: false, completion: {
docController.presentPreview(animated: true)
})
Run Code Online (Sandbox Code Playgroud)
只要在视图控制器的其他地方我就有这个:
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
Run Code Online (Sandbox Code Playgroud)
我很高兴去。我无法解决的是如何将它应用到 UIViewControllerRepresentable 并让它在 SwiftUI 中工作。我的 UIViewControllerRepresentable 是否应该以成为 UIViewController 为目标?那么我如何设置委托和presentPreview?这会像我的标准 iOS 应用程序一样覆盖任何视图并全屏显示在我的 SwiftUI 应用程序上吗?谢谢