Skip to content

fix(ios): fix URL resolution when external frameworks are loaded #7831

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daniellacosse
Copy link

@daniellacosse daniellacosse commented Jan 16, 2025

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:

[pageProxyID=16, webPageID=17, PID=50534] WebPageProxy::didFailProvisionalLoadForFrame: 
frameID=1, isMainFrame=1, domain=NSCocoaErrorDomain, code=256, isMainFrame=1, 
willInternallyHandleFailure=0

I traced the source of the error to this Router.swift file and discovered that when I didn't call any gomobile-compiled function, the result of pathUrl was different. According to the Swift Foundation source, URL(fileURLWithPath:)

    /// Initializes a newly created URL using the contents of the given data, 
relative to a base URL.

So it seems that somehow (I don't fully understand it), accessing the .xcframework in the running code changes the base URL that URL(fileURLWithPath:) starts from. By adding the basePath in 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:

Screenshot 2025-01-16 at 4 26 34 PM

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

Successfully merging this pull request may close these issues.

1 participant