0
我的應用程序未打開HealthKit權限屏幕,用戶可以在其中允許訪問Healthkit。 我收到手錶上的屏幕顯示我的應用程序「想要訪問您的健康數據」。但手機只是移動到應用程序啓動屏幕,然後第一頁,而不是提出設置。沒有錯誤。該應用編碼如下以請求授權。有任何想法嗎?HealthKit權限不打開
在電話AppDelegate中:
import UIKit
import WatchConnectivity
import HealthKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, WCSessionDelegate {
var window: UIWindow?
let healthStore = HKHealthStore()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
WatchSessionManager.sharedManager.startSession()
return true
}
// authorization from watch
func applicationShouldRequestHealthAuthorization(application: UIApplication) {
let healthStore = HKHealthStore()
let quantityType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
let calorieQuantityType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)
let dataTypesToRead = NSSet(objects: HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!, HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!)
healthStore.requestAuthorizationToShareTypes(nil, readTypes: dataTypesToRead as! Set<HKObjectType>, completion: { (success, error) in
if success {
} else {
print(error!.description)
}
})
healthStore.handleAuthorizationForExtensionWithCompletion { success, error in
}
}