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

fix(ios): return proper mimeType on M1 x86_64 simulators #5853

Merged
merged 5 commits into from
Aug 18, 2022
Merged

fix(ios): return proper mimeType on M1 x86_64 simulators #5853

merged 5 commits into from
Aug 18, 2022

Conversation

arnold-plakolli
Copy link
Contributor

@arnold-plakolli arnold-plakolli commented Aug 12, 2022

In one of the projects I'm working on we are having an issue of app getting stuck on white screen in iOS simulators 14.0+ that run on M1 machines.

After much trial and error we found out that in the ios/Capacitor/Capacitor/WebViewAssetHandler.swift file, the method mimeTypeForExtension was returning default application/octet-stream value for many path extensions. In real devices or simulators with lower iOS versions, it was returning correct value.

The issue was with the object UTTypeCreatePreferredIdentifierForTag. This object was returning nil value and as a result the method was defaulting to the value application/octet-stream.

This happens for projects:

  • With checked Open using Rosetta option for Xcode
  • With unchecked Open using Rosetta option for Xcode
    • Forcing architecture x86_64 for simulator builds

UTTypeCreatePreferredIdentifierForTag is marked as deprecated and Xcode suggested using UTType instead. I did that but with same result as before.

I ended up providing a dictionary of path extensions and mime types. I added the dictionary as a fallback in case UTTypeCreatePreferredIdentifierForTag returns nil.

Issue environment:

  • Machine: M1 Mac (Apple Silicon)
  • iOS Simulator: 14.0+

Sample projects:

closes #5793

@jcesarmobile
Copy link
Member

have you tried turning off Open using Rosetta (uncheck the checkbox) and restarting the computer?
for me just unchecking the checkbox had no effect, I had to restart the computer.
Also needed to do a Product -> Clean Build Folder from Xcode before running

@arnold-plakolli
Copy link
Contributor Author

arnold-plakolli commented Aug 18, 2022

have you tried turning off Open using Rosetta (uncheck the checkbox) and restarting the computer? for me just unchecking the checkbox had no effect, I had to restart the computer. Also needed to do a Product -> Clean Build Folder from Xcode before running

@jcesarmobile I did that for the blank Ionic project and it did work. The simulator loaded the app and it did not get stuck on the white screen.

However when I ran the project, in which I initially had this bug on, it still showed the white screen.

When I looked at the project build settings, I noticed that it was forcing architecture x86_64 for simulators and that's when UTTypeCreatePreferredIdentifierForTag returns nil.

So it seems this fix is still valid for projects:

  • With checked Open using Rosetta option for Xcode
  • With unchecked Open using Rosetta option for Xcode
    • Forcing architecture x86_64 for simulator builds

I'll update the PR description as well to reflect these findings.

Thanks @jcesarmobile

@jcesarmobile
Copy link
Member

You mean the project you shared or a different project?

where is that setting for using x86_64 on simulators?

@arnold-plakolli
Copy link
Contributor Author

arnold-plakolli commented Aug 18, 2022

@jcesarmobile

The project I originally encountered the bug on is a different project not the one I shared.

I updated the PR description that points to two sample projects which both force arch x86_64 for simulator builds. One of the projects points to version 4.0.1 of @capacitor/ios and the other one points to the fixed version in this PR. You can run them both with Open using Rosetta unchecked and you can see that the one that points to version 4.0.1 shows a blank screen. At least that's what I encountered on my tests.

@jcesarmobile jcesarmobile changed the title Fixed issue #5793 fix(ios): return proper mimeType on M1 x86_64 simulators Aug 18, 2022
Accommodating the big MIME list
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.

bug: MIME Types ignored/blocked in strict mode
3 participants