在我的手錶擴展我調用這個函數: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")
一旦你拒絕授權,你只能在設置中打開它。或者重新安裝應用程序。 – Lumialxk
我從來沒有拒絕授權。我試圖重新安裝應用程序,我仍然從未獲得權限表。 – raginggoat
您正在使用哪個iOS版本? – Mehul