gpt4 book ai didi

ios - 在 HealthKit 中请求授权 : why the result is always successful?

转载 作者:行者123 更新时间:2023-11-28 14:31:19 25 4
gpt4 key购买 nike

我请求访问某些健康信息只是为了以这种方式阅读:

let healthStore = HKHealthStore()
let types: Set<HKObjectType> = [distanceWalkingRunning]

healthStore.requestAuthorization(toShare: nil, read: types) { (success, error) in
completion(success, error)
}

然后,当第一次启动应用程序时,我看到了标准对话框,让我选择是否允许健康访问信息。如果我点击“不允许”,则会显示警告 View :

Health Access - You can turn on health data categories later in the Health app.

他们,警报和健康访问对话框都被取消,并显示应用程序的登录屏幕。我可以看到 healthStore.requestAuthorization 方法调用中提供的 completion 闭包正在获取 successtrue 值参数和 nil 无论如何都是 error 参数。

我怎么知道用户不允许访问健康?

最佳答案

documentation success 参数读取:

A Boolean value that indicates whether the request was processed successfully. This value does not indicate whether permission was actually granted. This parameter is false if an error occurred while processing the request; otherwise, it is true.

在初始请求和后续请求中,请求都已成功处理,您将获得 true 表示 success

您无法查明用户是否已授予对您请求的数据的读取权限。同样,来自 the documentation :

To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store.

提交授权请求后,您只需尝试读取数据,您要么获得它,要么似乎没有可用数据。

关于ios - 在 HealthKit 中请求授权 : why the result is always successful?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51231371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com