HealthKit许可表未出现 [英] HealthKit Permission Sheet Not Appearing
问题描述
在我的观看分机中,我调用此函数:
func requestAuthorization(){
let healthStore = HKHealthStore( )
let workoutType = HKObjectType.workoutType()
let heartRateType = HKObjectType.quantityType(forIdentifier:.heartRate)
//读取
let readingTypes = Set([ heartRateType!,workoutType])
//写作
let writingTypes = Set([heartRateType!,workoutType])
// auth request
healthStore .requestAuthorization(toShare:writingTypes,read:readingTypes){(success,error) - >如果错误,则
无效!= nil {
print(error \(error?.localizedDescription))
}否则成功{
self.startButton .setEnabled(true)
}否则如果!success {
self.startButton.setEnabled(false)
}
}
}
在AppDelegate.swift中,我有:
func applicationShouldRequestHealthAuthorization(_ application:UIApplication){
let healthStore = HKHealthStore()
healthStore.handleAuthorizationForExtension {(success,error) - >无效
// ...
}
}
我在手表和手机上显示对话框,当我从对话框中告诉它时,它会在手机上打开应用程序。我遇到的问题是手机应用程序不显示应该显示的权限表以允许权限。此处提到了权限表:
编辑:我从requestAuthorization()方法调用中打印出此错误。
错误可选(app \的Info.plist中不存在必需的用法说明字符串)
使用此。
In my watch extension I call this function:
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)
}
}
}
And in AppDelegate.swift, I have:
func applicationShouldRequestHealthAuthorization(_ application: UIApplication) {
let healthStore = HKHealthStore()
healthStore.handleAuthorizationForExtension { (success, error) -> Void in
//...
}
}
I get the dialog on my watch and phone and it opens the app on the phone when I tell it to from the dialog. The issue I'm having is that the phone app doesn't display the permission sheet that should show up in order to allow permissions. The permission sheet is mentioned here: https://developer.apple.com/reference/healthkit
What do I need to do to get it to appear so permissions can be granted? As it stand right now, I can grant permissions by going to the Health app then sources and select my app and grant the permissions that way.
The permission sheet I'm talking about is this.
EDIT: I'm getting this error printed from the requestAuthorization() method call.
error Optional("Required usage description strings not present in app\'s Info.plist")
With this TestHealthKit, I was able to open the health-kit permission sheet.
// 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;
}
}
Also, check have you enabled the entitlement as shown. .
这篇关于HealthKit许可表未出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!