Search code examples
iosswift

SensorKit - Fetching data don't call results delegate function


Recently we got approved by Apple to use SensorKit. Here are all prerequisites I checked:

  • I'm pretty sure the project is configured properly. Entitlements file contains list of all sensors, Info.plist contains NSSensorKitUsageDescription, NSSensorKitUsageDetail and NSSensorKitPrivacyPolicyURL.
  • When I request authorization for a sensor (e.g. accelerometer) the system dialog is presented, I approve it and it's clearly allowed in phone Settings -> Privacy -> Research Sensor & Usage Data section
  • I started recording for a sensor
  • I waited more than 24h (6 days actually)
  • I created SRFetchRequest (see the code below) with correct time interval
let now = Date()
let from = Date(timeInterval: -3 * 24 * 60 * 60, since: now) as NSDate
let to = Date(timeInterval: -2 * 24 * 60 * 60, since: now) as NSDate

let request = SRFetchRequest()
request.device = SRDevice.current
request.from = from.srAbsoluteTime
request.to = to.srAbsoluteTime
reader.fetch(request)

What's interesting, no error is triggered. Actually the func sensorReader(_ reader: SRSensorReader, didCompleteFetch fetchRequest: SRFetchRequest) delegate method is invoked but func sensorReader(_ reader: SRSensorReader, fetching fetchRequest: SRFetchRequest, didFetchResult result: SRFetchResult<AnyObject>) -> Bool method never gets called.

Did anyone make it working? Any ideas why it's not working?


Solution

  • For those interested I found an issue. I tried to collect them from my Apple Watch series 3 that are probably not supported. With series 6 (or from iPhone) it works correctly. Interestingly devices support isn't documented anywhere...