fix(ios): fix URL resolution when external frameworks are loaded #7831
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.
I'm not 100% sure if this fixes the issue I was encountering in all cases but here's the lowdown:
I'm loading an xcframework compiled by gomobile into the xcode project that Capacitor creates. There was this mysterious behavior where as soon as I called any function exposed by that library, my app wouldn't load and I'd get the following error:
I traced the source of the error to this
Router.swiftfile and discovered that when I didn't call any gomobile-compiled function, the result ofpathUrlwas different. According to the Swift Foundation source,URL(fileURLWithPath:)So it seems that somehow (I don't fully understand it), accessing the
.xcframeworkin the running code changes the base URL thatURL(fileURLWithPath:)starts from. By adding thebasePathin here, I think we're now enforcing a consistent URL base, and my app appears to work now whether I call a method from my library or not.Here is a photo of it working with the fix: