2016-10-04 40 views
0

如何爲我的健康套件授權添加第二個HKQuantityType? 我想補充的心臟速率和燒燬的能量都作爲QuantityTypes的陣列。當我在'let dataTypes = Set(arrayLiteral:quantityTypes)'而不是數量類型這兩行中添加這兩個類型時,我收到一個錯誤:「無法將HKQuantityType的值轉換爲期望的參數類型[]如何爲健康套件授權添加HKQuantityType數組

我是初學者,我覺得我不是正確格式化陣列。

guard let heartRateQuantityType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned) else { 
     // displayNotAllowed() 
     return 
    } 

    guard let calorieQuantityType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned) else { 
     // displayNotAllowed() 
     return 
    } 

    let quantityTypes = [calorieQuantityType, heartRateQuantityType] 
    let dataTypes = Set(arrayLiteral: quantityTypes) 
    healthStore.requestAuthorizationToShareTypes(nil, readTypes: dataTypes) { (success, error) -> Void in 
     if success == false { 
      // self.displayNotAllowed() 
     } 
    } 

回答

0

要設置陣列的設置,則請求授權,而是添加calorieQuantityType和heartRateQuantityType到SET直接

//delete this let quantityTypes = [calorieQuantityType, heartRateQuantityType] 
let dataTypes = Set([calorieQuantityType, heartRateQuantityType]) 
healthStore.requestAuthorizationToShareTypes(nil, readTypes: dataTypes) { (success, error) -> Void in 
    if success == false { 
     // self.displayNotAllowed() 
    } 
}