Native apps (content updates)
Update images, JSON, strings and web content in native Kotlin/Java and Swift apps over the air.
Native Android and iOS apps can't replace their code over the air, but they can replace the content they show. The CodeOnAir content SDKs use the same deployments, keys and CLI as React Native CodePush to ship a folder of files to your app.
What you can and can't update#
| Can update | Can't update |
|---|---|
| Images, icons, banners | Kotlin, Java or Swift code |
| JSON and config files, feature copy | Native libraries (.so, frameworks) |
| Localized strings you load yourself | AndroidManifest.xml, Info.plist, entitlements, permissions |
| HTML, CSS and JS shown in a WebView / WKWebView | Compiled resources (res/, asset catalogs, storyboards) |
| Lottie animations, fonts you load from files | Anything that changes what the app does |
Install#
dependencies {
implementation("com.codeonair:content-updates-android:1.0.0")
}.package(url: "https://github.com/codeonair/codepush-ios.git", from: "1.0.0")
Use your platform's deployment key from CodePush → Android / iOS. On Android put it in AndroidManifest.xml as <meta-data android:name="com.codeonair.CODEPUSH_DEPLOYMENT_KEY" android:value="cpd_…" />; on iOS add CodePushDeploymentKey to Info.plist. The server defaults to https://app.codeonair.com.
Ship content with the app#
Put the content the app starts with in src/main/assets/codeonair-content/ (Android) or a blue folder reference named codeonair-content (iOS). Until a release is installed, the SDK reads these files; they're never changed or deleted.
Use it#
CodeOnAirContent.init(this)
CodeOnAirContent.addListener { reloadScreens() } // new content is active
CodeOnAirContent.sync(SyncOptions().apply { installMode = InstallMode.ON_NEXT_RESUME })
val banner: File? = CodeOnAirContent.file("images/banner.png")
val copy: String? = CodeOnAirContent.readText("strings/en.json")
webView.settings.allowFileAccess = true // off by default since Android 11
webView.loadUrl("file://" + CodeOnAirContent.contentDir() + "/index.html")CodeOnAirContent.start()
CodeOnAirContent.onContentUpdated { _ in reloadScreens() }
CodeOnAirContent.sync(SyncOptions(installMode: .onNextResume))
let banner = CodeOnAirContent.url(for: "images/banner.png")
let copy = CodeOnAirContent.string(for: "strings/en.json")| Install mode | When new content becomes active |
|---|---|
IMMEDIATE | Right away; your listener reloads the screen. Default for mandatory releases. |
ON_NEXT_RESTART | On the next cold start. Default for optional releases. |
ON_NEXT_RESUME | When the app comes back from the background, after minimumBackgroundDuration seconds away. |
ON_NEXT_SUSPEND | While the app is in the background (after minimumBackgroundDuration), so the user comes back to it. |
No process restart is needed: the SDK switches the active folder and calls your listener.
Release#
codeonair-codepush release shop-android ./content 1.2.0 -d "Spring banner" codeonair-codepush release shop-ios ./content 1.2.x --mandatory
Each release is a complete snapshot of the folder, so relative links (HTML to images) keep working. History, rollouts, patch and rollback work the same as for React Native.
Safety#
- Every download is checked against its SHA-256 and unpacked into a new folder before it's used; the switch is a single atomic write.
- New content must be confirmed with
notifyReady()(sync()does it for you). If the app is restarted without that, the next launch goes back to the previous content, reports the failure, and skips that release on the device from then on. - A new app build (version or build number) starts on its bundled content again.