2016-11-29 64 views

回答

-1

我得到了答案。移動目標可從HKActivitySummary訪問。

您應該請求權限讀取HKActivitySummaryType:

let activitySummaryType = HKActivitySummaryType.activitySummaryType() 
let readDataTypes: Set<HKObjectType> = [activitySummaryType] 
healthStore.requestAuthorization(toShare: nil, read: readDataTypes, completion: myCompletionHandler) 

然後使用HKActivitySummaryQuery閱讀摘要信息

let query = HKActivitySummaryQuery(predicate: myPredicate) { (query, summaries, error) -> Void in 
    if error != nil { 
     fatalError("*** Did not return a valid error object. ***") 
    } 

    if let activitySummaries = summaries { 
     for summary in activitySummaries { 
      print(summary.activeEnergyBurnedGoal) 
      //do something with the summary here... 
     } 
    } 
} 
healthStore.execute(query) 

是從HKActivitySummary抵達酒店here其他活動的彙總數據。

+0

您的示例不完整。我將你的代碼複製到一個新的項目中,我無法實現它的工作。 – Neo42

相關問題