fix(ios): Prevent infinite value in returned location data causing app crash #231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
iOS
Motivation and Context
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
Check the
NSMutableDictionary
constructed from the nativeCLLocation
data is valid for conversion to JSON usingisValidJSONObject
before attempting conversion.Testing
As outlined in #230, I'm not certain exactly which value retrieved from the
CLLocation
object isINFINITY
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 theNSMutableDictionary
contains theINFINITE
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 ofCDVLocation.m
: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
(platform)
if this change only applies to one platform (e.g.(android)
)