SmogWatch icon indicating copy to clipboard operation
SmogWatch copied to clipboard

can't show PM10 data on Apple Watch

Open zinwalin opened this issue 5 years ago • 4 comments

image image image

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.

zinwalin avatar Jul 16 '20 03:07 zinwalin

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()
}

mackuba avatar Sep 02 '20 23:09 mackuba

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.

image

zinwalin avatar Sep 05 '20 00:09 zinwalin

In what way it didn't work?

mackuba avatar Sep 06 '20 20:09 mackuba

In what way it didn't work?

image

zinwalin avatar Sep 07 '20 01:09 zinwalin