Porting an existing iOS app with widgets to visionOS
In the process of getting my apps ready for running on visionOS, I seemed to be running into a real problem getting them to run as ‘proper’ visionOS apps because they have widgets.
As you may know, widgets get embedded into the iOS app, so they will become part of the binary and that is the problem. Luckily, I had posted this on Mastodon and got a quick response from the very knowledgeable Steve Troughton-Smith. You can see the fix here. I’m very grateful, as I’m sure I wouldn’t have found this out on my own.
If you can’t see the image or the post goes away, here’s basically what you need to do.
- Add the visionOS destination to your app target
- Go to the Build Phases section
- Go to Embed App Extensions (it may be called Embed Foundation Extensions instead)
- In the entry for the widget, click on the filter column. By default, it will probably say all platforms.
- Untick all platforms and ensure all the platforms you want apart from visionOS are ticked.
- Compile your app into a visionOS app
- Optionally remove all references in your targets to ‘designed for visionOS’ from your targets. In particular, you may find your widget will have this target, as it is pointless now.
And that’s it, you can now have the look of visionOS for your app and take advantage of the new features.