SmogWatch
SmogWatch copied to clipboard
can't show PM10 data on Apple Watch

I try with same parameters on Postman, which works. and then I hardcode those params for Apple watch extensions as show above, but failed to fetch data on apple watch.
Hi! Sorry, I missed the notification email then :(
If you're still interested in this, it looks like the problem was very simple - in one of the data series, for a different parameter (CO I think?) the returned values were listed as numbers, not as strings. And the parsing code in init(from decoder:) was throwing an error, because it assumed it always needs to parse the value from a string first.
This seems to fix it:
if let timestamp = try? Int(container.decode(String.self)) {
self.date = Date(timeIntervalSince1970: TimeInterval(timestamp))
} else {
throw InvalidValueError()
}
if let value = try? Double(container.decode(String.self)) {
self.value = value
} else if let value = try? container.decode(Double.self) {
self.value = value
} else {
throw InvalidValueError()
}
Hi! Sorry, I missed the notification email then :(
If you're still interested in this, it looks like the problem was very simple - in one of the data series, for a different parameter (CO I think?) the returned values were listed as numbers, not as strings. And the parsing code in
init(from decoder:)was throwing an error, because it assumed it always needs to parse the value from a string first.This seems to fix it:
if let timestamp = try? Int(container.decode(String.self)) { self.date = Date(timeIntervalSince1970: TimeInterval(timestamp)) } else { throw InvalidValueError() } if let value = try? Double(container.decode(String.self)) { self.value = value } else if let value = try? container.decode(Double.self) { self.value = value } else { throw InvalidValueError() }
without this changes, it works on Apple Watch simulator, but even compile with your changes, it still not worked on real apple watch.

In what way it didn't work?
In what way it didn't work?
