簡體   English   中英

遷移到Xcode 8和Swift 3.0時,Xcode Healthkit授權函數錯誤

[英]Xcode Healthkit authorized function error when migrate to Xcode 8 and Swift 3.0

以下函數在Xcode 7.3和Swift 2. *中工作,遷移到Xcode 8和Swift 3.0后,當我嘗試編譯時出現以下錯誤

不能調用非函數類型的值((Bool, _ error:NSError?) -> Void)!

     func authorizeHealthKit(_ completion: ((_ success:Bool, _ error:NSError?) -> Void)!) {
            healthKitStore = HKHealthStore()
            let typesSet:Set<HKSampleType> = [
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyTemperature)!,
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.respiratoryRate)!,
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureSystolic)!,
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureDiastolic)!, 
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass)!, 
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!,
                    HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.oxygenSaturation)!]


                healthKitStore?.requestAuthorization(toShare: typesSet, read: typesSet, completion: { (boolVal, error) in
                    completion(success: boolVal, error: error)   //<-- compile error here
            })
     }

嘗試使您的完成處理程序可選如下:

完成?(成功:boolVal,錯誤:錯誤)

另請注意Apple API文檔:

重要信息iOS 10.0上或之后鏈接的iOS應用程序必須在其Info.plist文件中包含其需要訪問的數據類型的使用說明密鑰,否則將崩潰。 要專門訪問和更新HealthKit數據,它必須分別包含NSHealthShareUsageDescription和NSHealthUpdateUsageDescription鍵。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM