【发布时间】:2016-11-24 03:06:39
【问题描述】:
在我的手表扩展中,我调用了这个函数:
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")
【问题讨论】:
-
一旦你拒绝授权,你只能在设置中打开这个。或者重新安装应用。
-
我从未拒绝过授权。我尝试重新安装该应用程序,但仍然没有获得许可表。
-
您使用的是哪个 iOS 版本?
-
@Mehul iOS 10.1.1 和 watchOS 3.1
-
您设法解决了这个问题吗?我在 10.3b6 / 3.1.3 中看到了同样的情况
标签: ios swift watchkit healthkit