【问题标题】:watchOS 9 WidgetKit complications missing com.apple.developer.healthkit entitlementwatchOS 9 WidgetKit 并发症缺少 com.apple.developer.healthkit 权利
【发布时间】:2022-11-05 09:40:57
【问题描述】:

我有一个去年推出的 iOS/wOS 应用程序。现在我想为它添加复杂性,并使用 WidgetKit 处理复杂性的新方法。我已经准备好了一切,直到我应该从 Health 中读取数据以显示它,但它以Missing com.apple.developer.healthkit entitlement 失败。

这是我添加的新扩展

它嵌入在 WatchKit 应用程序中,而不是在 WatchKit 扩展中,我已经添加了直接在 info.plist 中读取健康数据的权限。

我从TimelineProvider 协议方法中提取数据

 func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        let currentDate = Date()
        
        var entries: [WorkoutEntry] = []
        
        ComplicationHealthManager.loadPreviousWorkouts { workout in
            let workoutEntry = WorkoutEntry(date: currentDate, workout: workout)
            entries.append(workoutEntry)
            
            let timeline = Timeline(entries: entries, policy: .after(currentDate))
            completion(timeline)
        }
    }

在小型经理班的帮助下

class ComplicationHealthManager: ObservableObject {
    static func loadPreviousWorkouts(completion: @escaping (HKWorkout?) -> Void) {
        let healthStore: HKHealthStore = HKHealthStore()
        let workoutPredicate = HKQuery.predicateForWorkouts(with: .traditionalStrengthTraining)
        let compound = NSCompoundPredicate(andPredicateWithSubpredicates:
                                            [workoutPredicate])
        
        let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate,
                                              ascending: false)
        
        let query = HKSampleQuery(
            sampleType: .workoutType(),
            predicate: compound,
            limit: 0,
            sortDescriptors: [sortDescriptor]) { (query, samples, error) in
                guard
                    let samples = samples as? [HKWorkout],
                    error == nil
                else {
                    completion(nil)
                    return
                }
                
                let calendar = Calendar.current
                let todaysSamples = samples.filter{ calendar.isDateInToday($0.endDate) }.last
                
                completion(todaysSamples)
            }
        
        healthStore.execute(query)
    }
}

问题在于健康查询的关闭,它返回时没有锻炼,但有一个错误说明

Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}

这里的问题是我不明白在哪里以及如何为复杂功能扩展或 WatchKit 应用程序添加权利,因为它们都没有健康选项。我为 iPhone 应用程序和 WatchKit 扩展设置了健康权利。

【问题讨论】:

    标签: healthkit watchos widgetkit


    【解决方案1】:

    请为此在 feedback.apple.com 上提交反馈。

    您可以手动将 HealthKit 权利添加到与目标关联的 Code Signing Entitlements 文件(如果还没有,则创建一个新的)

    <key>com.apple.developer.healthkit</key>
    <true/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 2018-09-12
      相关资源
      最近更新 更多