Search code examples
iosios10ios-app-extensionimessageimessage-extension

Can an iMessage App extension use View Controllers defined in the host app?


When creating an iMessage app that is an extension of an existing iOS app, can the iMessage app use View Controllers that were defined in the host app?

For example, let's say I have an iOS app that allows you to book meetings and it has a Calendar view where meetings are displayed. In my iMessage app extension, I want to be able to display that same exact Calendar view. Can I use that CalendarViewController defined in the iOS app or do I have to re-create that UI again in the iMessage app extension?


Solution

  • Yes, you just need to make sure the code and storyboards are added to both the main app and iMessage extension targets. There are a couple of ways to do it.

    You can see which targets a specific file belong to by looking at the File Inspector, like so:

    View Controller added to multiple targets

    You can also look in the Build Phases for the target and see which sources are being compiled or which resources are being bundled, and add/remove files as needed:

    Build Phases