0
当我调用以下函数来读取dataOfBirth时,我在设备上测试时一直收到错误的访问错误。我在Xcode 7测试EXC_BAD_ACCESS在HealthKit中读取dateOfBirthWithError
func updateUsersAge(){
do{
var error : NSError!
let birthdate = try currentHealthStore.dateOfBirthWithError()
let now = NSDate()
let dateComponents = NSCalendar.currentCalendar().components(NSCalendarUnit.NSYearCalendarUnit, fromDate: birthdate, toDate: now, options: NSCalendarOptions.WrapComponents)
let age = dateComponents.year
self.ageValueLabel.text = NSNumberFormatter.localizedStringFromNumber(NSNumber(integer: age), numberStyle: NSNumberFormatterStyle.NoStyle)
}
catch{
print("Not avaialble")
}
}
currentHealthStore在AppDelegate中定义为全局变量使用夫特2.0:
let currentHealthStore = HKHealthStore()
并且在接收到错误一旦这一行被执行:
let birthdate = try currentHealthStore.dateOfBirthWithError()
您是否在调试器中使用了dateOfBirthWithError()的代码? – Gruntcakes
是的,没有显示在调试器中,一旦它开始执行此行,我收到此错误 –
发布dateOfBirthWithError的代码? – Tim