func sensorReader(_ reader: SRSensorReader, fetching fetchRequest: SRFetchRequest, didFetchResult result: SRFetchResult<AnyObject>) -> Bool {
print("sensorReader(_:fetching:didFetchResult:) method called")
guard let ambientSample = result.sample as? SRAmbientLightSample else {
print("Unexpected sample type: (type(of: result.sample))")
return true
}
let luxValue = ambientSample.lux.value
let timestamp = Date(timeIntervalSinceReferenceDate: result.timestamp.rawValue)
print("Ambient light sample: lux value = (luxValue) lux, timestamp = (timestamp)")
// Check if the data is between 24 hours and 72 hours old
let twentyFourHoursAgo = Date().addingTimeInterval(-24 * 60 * 60)
let seventyTwoHoursAgo = Date().addingTimeInterval(-72 * 60 * 60)
if timestamp >= seventyTwoHoursAgo && timestamp <= twentyFourHoursAgo {
DispatchQueue.main.async {
let dataPoint = AmbientLightDataPoint(timestamp: timestamp, lux: Float(luxValue))
self.ambientLightData.append(dataPoint)
print("Added ambient light data: (luxValue) lux, Timestamp: (timestamp)")
}
self.displayAmbientLightData(sample: ambientSample)
} else {
print("Data ignored as it is outside the 24 to 72-hour window: (luxValue) lux, Timestamp: (timestamp)")
}
return true // Indicates no further processing is needed
}
It’s a question about implementing SensorKit Deligate. Currently, you can add entry with all the privileges to get device information.
But why isn’t only the value of didFetchResult that gets the illuminance value called out of the deligate methods.. Other deligate methods are called well (ex device call related method, didCompleteFetch, etc.) Please help
The permissions to the SensorKit are normally received and data can be called, including other Deligate methods and permission settings. Currently, the illumination values that can be shared within the actual device are checked, but the method calling the Deligate illumination value in the code is not called.
Sijong Kim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5