2016-09-17 58 views
1

以下函數在Xcode 7.3和Swift 2中工作* *,在遷移到Xcode 8和Swift 3.0後出現以下錯誤當我嘗試編譯時Xcode Healthkit授權功能錯誤遷移到Xcode 8和Swift 3.0時

cannot call value of non-function type ((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 
      }) 
    } 
+0

[如何使用Markdown或HTML格式化我的帖子](http://stackoverflow.com/help/formatting) – buhtz

回答

0

嘗試使你完成處理器可選如下:?

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

而且從蘋果API documentatio要注意n:

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

希望這會有所幫助。