【问题标题】:Puzzling error inserting data into HKWorkoutRouteBuilder in watchOS 4 Beta 4在 watchOS 4 Beta 4 中将数据插入 HKWorkoutRouteBuilder 的令人费解的错误
【发布时间】:2023-03-13 02:48:01
【问题描述】:

当我将路线数据插入 HKWorkoutRouteBuilder 时,我收到以下错误:

与名为 com.apple.healthd.server 的服务的连接被中断,但消息是通过额外的代理发送的,因此该代理无效

这是一个代码 sn-p。

    workoutRouteBuilder.insertRouteData(filteredLocations) { (success, error) in
        if !success {
            print("inserting route data failed with error: \(String(describing: error))")
        }
    }

我通过 Speed Sloth 示例的实施进行了模式化。

任何见解都将不胜感激!

更新: 以下是观看日志中的更多信息。看起来像是某种权限问题,但我还没有找到它:

故障 13:21:14.664262 -0400 健康 来自 pid 1705 的连接:警告:调用期间捕获到异常 收到的消息,丢弃传入的消息并使 联系。例外:无效参数不满足: [authorizationStatuses 计数] == [typesIncludingParentTypes 计数] 无效参数不满足:[authorizationStatuses count] == [typesIncludingParentTypes 计数] ( 0 CoreFoundation
0x1dc04d25 + 153 1 libobjc.A.dylib
0x1d227181 objc_exception_throw + 39 2 核心基础
0x1dc04be5 + 1 3 基础
0x1e43c1cd + 93 4 健康守护进程
0x2edf678f + 2015 5 健康守护进程
0x2ee6eed1 + 143 6 健康守护进程
0x2ee6ec77 + 143 7 健康守护进程
0x2ee7b99b + 485 8 健康守护进程
0x2f0e1e1f + 143 9 基础
0x1e589393 + 19 10 基础
0x1e587

【问题讨论】:

    标签: healthkit watchos-4


    【解决方案1】:

    我遇到了同样的问题。您需要确保向用户请求授权:

    // Objective C
    [HKSeriesType workoutRouteType]
    
    // Swift
    HKSeriesType.workoutRoute()
    

    【讨论】:

    • 谢谢!那成功了!我不敢相信我错过了。当然,一个更具描述性的错误消息会很好。
    • 应改进同意的错误。此外,当用户必须授予位置访问权限以使其仍然有用时,将其作为权限要求似乎权限超载。 PS随时将此作为公认的答案;)
    • 救了我!缺少 HKSeriesType.workoutRoute() 并花了我一天时间找到该权限密钥 - 苹果文档没有提到这一点
    【解决方案2】:

    与名为 com.apple.healthd.server 的服务的连接是 中断,但消息是通过额外的代理发送的,并且 因此此代理已失效

    看到此消息表明处理请求的系统进程已崩溃或退出。您应该向 Apple 提交错误。查找运行状况良好的崩溃日志并将其包括在内。

    【讨论】:

    • 是否可以从模拟器中获取healthd 的崩溃日志?我在控制台中找不到对healthd 的任何引用。
    【解决方案3】:

    别忘了在 AppDelegate 中为 HKHealthStore 添加 WorkoutRoute 的请求

    锻炼路线不适用于模拟器,仅适用于某些 HKWorkoutActivityType,例如 .walking,.running 在 OS4 上

    private func requestAccessToHealthKit() {
    
        let healthStore = HKHealthStore()
    
        let allTypes = Set([HKObjectType.workoutType(),
                            HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
                            HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!])
        if #available(watchOS 4.0, *) {
            allTypes.insert(HKSeriesType.workoutRoute())
        }
        healthStore.requestAuthorization(toShare: allTypes, read: allTypes) { (success, error) in
            if !success {
                print(error?.localizedDescription ?? "")
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-07
      • 1970-01-01
      • 2015-10-28
      • 2011-10-07
      • 1970-01-01
      • 2021-10-26
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      相关资源
      最近更新 更多