There and back again: Data transfer on Apple Watch

RSS for tag

Discuss the WWDC21 session There and back again: Data transfer on Apple Watch.

Posts under wwdc21-10003 tag

5 Posts

Post

Replies

Boosts

Views

Activity

Index Out of Range when Graphing Heart Data using Date as xAxis
Hello! I am getting error Fatal error: Index out of range when trying to plot the heart rate for the past month with dates as its xAxis. Below is the code im using. Im using the Dateformatter to convert date to string and then NSString to get an Int. This is what im guessing is causing the error The goal is to have the xaxis be the date / time of the heart rate interval and the yaxis be the Beats per minute.  let startDate = Calendar.current.date(byAdding: .month, value: -1, to: Date())  let query = HKSampleQuery(sampleType: sampleType, predicate: predicate, limit: Int(HKObjectQueryNoLimit), sortDescriptors: [sortDescriptor]) { query, result, error in               guard let samples = result as? [HKQuantitySample] else {         return       }               for sample in samples {         let unit = HKUnit(from: "count/min")         let HR = sample.quantity.doubleValue(for: unit)                     let dateFormatter = DateFormatter()       let startDate = dateFormatter.string(from: sample.startDate)       let dateInt = (startDate as NSString).integerValue                 var yValues = [ChartDataEntry]()                   yValues.append(ChartDataEntry(x: Double(dateInt), y: HR))                 let set1 = LineChartDataSet(entries: yValues, label: "Test")                 let data = LineChartData(dataSet: set1)                 self.lineChartView.data = data                 }     }           store.execute(query)
2
0
511
May ’22
Watch App will not collect data when wrist is turned
I currently am working on an application that will collect sensor data on an Apple watch and then transfer it to an iPhone and then send it to my database. The biggest struggle I'm currently having is that I cannot get the watch to continue to collect data when the watch face is not pointed at the user. I have tried turning settings on within the watch and done some research on background activity within my app, but nothing is working. All I really need to be able to do is have the watch be always on/active and not "fall asleep" whenever the wrist is turned. This will allow me to continuously collect data and send it, even when the user is moving their hand around
0
0
710
Apr ’22
Index Out of Range when Graphing Heart Data using Date as xAxis
Hello! I am getting error Fatal error: Index out of range when trying to plot the heart rate for the past month with dates as its xAxis. Below is the code im using. Im using the Dateformatter to convert date to string and then NSString to get an Int. This is what im guessing is causing the error The goal is to have the xaxis be the date / time of the heart rate interval and the yaxis be the Beats per minute.  let startDate = Calendar.current.date(byAdding: .month, value: -1, to: Date())  let query = HKSampleQuery(sampleType: sampleType, predicate: predicate, limit: Int(HKObjectQueryNoLimit), sortDescriptors: [sortDescriptor]) { query, result, error in               guard let samples = result as? [HKQuantitySample] else {         return       }               for sample in samples {         let unit = HKUnit(from: "count/min")         let HR = sample.quantity.doubleValue(for: unit)                     let dateFormatter = DateFormatter()       let startDate = dateFormatter.string(from: sample.startDate)       let dateInt = (startDate as NSString).integerValue                 var yValues = [ChartDataEntry]()                   yValues.append(ChartDataEntry(x: Double(dateInt), y: HR))                 let set1 = LineChartDataSet(entries: yValues, label: "Test")                 let data = LineChartData(dataSet: set1)                 self.lineChartView.data = data                 }     }           store.execute(query)
Replies
2
Boosts
0
Views
511
Activity
May ’22
Watch App will not collect data when wrist is turned
I currently am working on an application that will collect sensor data on an Apple watch and then transfer it to an iPhone and then send it to my database. The biggest struggle I'm currently having is that I cannot get the watch to continue to collect data when the watch face is not pointed at the user. I have tried turning settings on within the watch and done some research on background activity within my app, but nothing is working. All I really need to be able to do is have the watch be always on/active and not "fall asleep" whenever the wrist is turned. This will allow me to continuously collect data and send it, even when the user is moving their hand around
Replies
0
Boosts
0
Views
710
Activity
Apr ’22