Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't show PM10 data on Apple Watch #3

Open
zinwalin opened this issue Jul 16, 2020 · 4 comments
Open

can't show PM10 data on Apple Watch #3

zinwalin opened this issue Jul 16, 2020 · 4 comments

Comments

@zinwalin
Copy link

zinwalin commented Jul 16, 2020

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.

@mackuba
Copy link
Owner

mackuba commented Sep 2, 2020

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

@zinwalin
Copy link
Author

zinwalin commented Sep 5, 2020

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

@mackuba
Copy link
Owner

mackuba commented Sep 6, 2020

In what way it didn't work?

@zinwalin
Copy link
Author

zinwalin commented Sep 7, 2020

In what way it didn't work?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants