Code Push for iOS Hybrid Apps
This guide explains how to use Shorebird in an iOS hybrid app scenario (that is, your app embeds Flutter UI in non-Flutter UI).
This guide assumes you have already have an iOS app and a Flutter module. Our
iOS app will be named IosCodePushDemo
and our Flutter module will be named
flutter_module
.
This guide also assumes that you have created a Shorebird account. If you have not created a Shorebird account, please see our code push guide for instructions.
The reference code for this guide is available at https://github.com/shorebirdtech/samples/tree/main/add_to_app.
First, run shorebird init
in your Flutter module:
First, we need to package our Flutter module for release. This will produce an
.xcframework
that we can embed in our iOS app and provide Shorebird with the
information it needs to apply patches.
To create a release, run the following the root directory of your Flutter module:
The release-version
parameter needs to match the version of the iOS app
that uses this module (i.e., version+build
from the Xcode settings, or
CFBundleShortVersionString+CFBundleVersion
from your app’s Info.plist).
The version number for this app would be 1.2.3+4
The ShorebirdFlutter.xcframework
and App.xcframework
artifacts produced by
the shorebird release
command will be placed in the release
directory in the
root of your Flutter module.
While there are multiple ways to embed a Flutter module in an iOS app, Shorebird requires that your Flutter module be embedded in your iOS app as an .xcframework.
In Xcode:
- Navigate to your app target’s “Build Settings” tab.
- Find the “Framework Search Paths” setting (the Filter field on the top right of the build settings tab is helpful for this).
- Add an entry to the “Framework Search Paths” list. This entry should be the
relative path to the directory containing
ShorebirdFlutter.xcframework
andApp.xcframework
artifacts. By default, these artifacts are placed in therelease
directory in the root of your Flutter module, but you should feel free to move them elsewhere if you prefer.
In the “General” tab of your app target, add App.xcframework
and
ShorebirdFlutter.xcframework
from to the “Frameworks, Libraries, and Embedded
Content” section. Make sure to select “Embed & Sign” for both frameworks.
In Xcode, update the current scheme’s build configuration to “Release”
Now run your app on a device (not a simulator). Your app should run as normal, and you should see debug logs from Shorebird.
We won’t cover this step in detail here, but this is where you would submit your
app to the App Store. For code push to work, it is important that you submit
with the same xcframework
generated by the release command above.
You can skip this step if you just want to see Code Push working in an app.
Make a user-visible change to the code in your Flutter module. Then run:
release-version
should be the version of the iOS app you released with the
output of the release
command. As before, this should match your app’s version
and build numbers in Xcode. The command above will patch the release we created
earlier in this guide.
You can now test the patch in your app by running the app from Xcode. After the app launches, you should see a logs from Shorebird informing you that the app is checking for new patches and saying that the patch was installed:
For the app to reflect the changes, you will need to close and reopen the app. Do this by stopping the app in Xcode and then running it again.