HealthKit权限表中不显示
问题描述:
在我的手表扩展我调用这个函数:HealthKit权限表中不显示
func requestAuthorization() {
let healthStore = HKHealthStore()
let workoutType = HKObjectType.workoutType()
let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)
//reading
let readingTypes = Set([heartRateType!, workoutType])
//writing
let writingTypes = Set([heartRateType!, workoutType])
//auth request
healthStore.requestAuthorization(toShare: writingTypes, read: readingTypes) { (success, error) -> Void in
if error != nil {
print("error \(error?.localizedDescription)")
} else if success {
self.startButton.setEnabled(true)
} else if !success {
self.startButton.setEnabled(false)
}
}
}
而在AppDelegate.swift,我有:
func applicationShouldRequestHealthAuthorization(_ application: UIApplication) {
let healthStore = HKHealthStore()
healthStore.handleAuthorizationForExtension { (success, error) -> Void in
//...
}
}
我得到的对话我的手表和手机和当我从对话框中告诉它时,它会打开手机上的应用程序。我遇到的问题是电话应用程序不显示应该显示的权限表以允许权限。这里提到权限表: https://developer.apple.com/reference/healthkit
我需要做些什么才能让它出现,以便授予权限?现在,我可以通过转到Health应用程序然后选择我的应用程序并以这种方式授予权限来授予权限。
编辑︰我从requestAuthorization()方法调用打印此错误。
error Optional("Required usage description strings not present in app\'s Info.plist")
答
有了这个TestHealthKit,我能打开健康套件许可表。
// 4. Request HealthKit authorization
(HealthStore as! HKHealthStore).requestAuthorizationToShareTypes(nil, readTypes: dataTypesToRead()) { (success, error) -> Void in
// self.CheckAuthorizationStatusFor(self.dataTypesToRead())
if (success)
{
SuccessCompletion(success: success)
return;
}
else
{
FailureCompletion(err: error)
return;
}
}
+0
这正是我所拥有的权利。如果我转到Apple Health应用程序并从那里向我的应用程序授予权限,我的应用程序中的所有内容都可以正常工作从字面上看,我遇到的唯一问题是,当手表应用程序请求手机的许可时,没有看到权限表,当我选择通过手机上的提示打开应用程序时,它会打开我的应用程序,但我没有看到权限片。 – raginggoat
一旦你拒绝授权,你只能在设置中打开它。或者重新安装应用程序。 – Lumialxk
我从来没有拒绝授权。我试图重新安装应用程序,我仍然从未获得权限表。 – raginggoat
您正在使用哪个iOS版本? – Mehul