dpa99c opened a new pull request #231: URL: https://github.com/apache/cordova-plugin-geolocation/pull/231
<!-- Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines: http://cordova.apache.org/contribute/contribute_guidelines.html Thanks! --> ### Platforms affected iOS ### Motivation and Context <!-- Why is this change required? What problem does it solve? --> <!-- If it fixes an open issue, please link to the issue here. --> As outlined in #230, the plugin is sometimes causing app crashes on iOS 14 because one of the values being extracted from the native location object has an infinite value and therefore an exception is raised when trying to extract the values and transform then into a JSON object. ### Description <!-- Describe your changes in detail --> Check the `NSMutableDictionary` constructed from the native `CLLocation` data is valid for conversion to JSON using [`isValidJSONObject`](https://developer.apple.com/documentation/foundation/nsjsonserialization/1418461-isvalidjsonobject?language=objc) before attempting conversion. ### Testing <!-- Please describe in detail how you tested your changes. --> As outlined in #230, I'm not certain exactly which value retrieved from the `CLLocation` object is `INFINITY` because the stack trace from the crash only points to the line where the conversion to JSON is attempted but doesn't actually indicate which field in the `NSMutableDictionary` contains the `INFINITE` value. However, the issue can be artificially reproduced by setting one of the values to `INFINITY` before the conversion is made, e.g. on [line 293 of `CDVLocation.m`](https://github.com/apache/cordova-plugin-geolocation/blob/master/src/ios/CDVLocation.m#L293): ``` [returnInfo setObject:[NSNumber numberWithDouble:INFINITY] forKey@"timestamp"]; ``` Without the changes this PR makes, the above will cause an app crash. With the changes this PR makes, the plugin will return a `POSITIONUNAVAILABLE` error and the app will not crash. ### Checklist - [x] I've run the tests to see all new and existing tests pass - [N/A] I added automated test coverage as appropriate for this change - [x] Commit is prefixed with `(platform)` if this change only applies to one platform (e.g. `(android)`) - [x] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/)) - [N/A] I've updated the documentation if necessary -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
