Migrating from CodePush
tip
This guide is for teams migrating from Microsoft CodePush. If you are starting fresh, follow the Quick Start instead.
Microsoft has retired AppCenter and CodePush. This guide walks you through switching to SwiftPatch in six steps.
Step 1: Install SwiftPatch SDK
npm uninstall react-native-code-push
npm install @swiftpatch/react-native
cd ios && pod install && cd ..
Step 2: Create Your App
Step 1: Sign up at app.swiftpatch.io.
Step 2: Create a new app.
Step 3: Copy your App ID from Settings.
Step 3: Add Native Credentials
iOS -- Info.plist:
ios/YourApp/Info.plist
<key>SwiftPatchAppId</key>
<string>YOUR_APP_ID</string>
Android -- strings.xml:
android/app/src/main/res/values/strings.xml
<string name="SwiftPatchAppId">YOUR_APP_ID</string>
Step 4: Update Native Code
Android -- MainApplication.kt:
- import com.microsoft.codepush.react.CodePush
+ import com.swiftpatch.SwiftPatchModule
override fun getJSBundleFile(): String? {
- return CodePush.getJSBundleFile()
+ return SwiftPatchModule.getJSBundleFile(applicationContext)
+ ?: super.getJSBundleFile()
}
iOS -- AppDelegate.swift:
- import CodePush
+ import react_native_swiftpatch
- func sourceURL(for bridge: RCTBridge!) -> URL! {
+ override func bundleURL() -> URL? {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
- return CodePush.bundleURL()
+ return SwiftPatchModule.getBundleURL()
#endif
}
Step 5: Update JavaScript
Replace the CodePush HOC:
- import codePush from 'react-native-code-push';
+ import { withSwiftPatch } from '@swiftpatch/react-native';
- const App = codePush({
- checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
- })(MyApp);
+ export default withSwiftPatch(MyApp, {
+ checkOnResume: true,
+ });
Replace imperative API calls:
- import codePush from 'react-native-code-push';
+ import { useSwiftPatch } from '@swiftpatch/react-native';
- codePush.sync({
- installMode: codePush.InstallMode.ON_NEXT_RESTART,
- });
+ const { checkForUpdate, downloadUpdate, installUpdate } = useSwiftPatch();
+ const update = await checkForUpdate();
+ if (update) {
+ await downloadUpdate();
+ await installUpdate();
+ }
Step 6: Install CLI and Deploy
npm install -g @swiftpatch/cli
swiftpatch login
swiftpatch deploy -p ios --hermes -n "Migration from CodePush"
tip
That is it. Your app is now using SwiftPatch. Deploy your first update and verify it works end-to-end before removing any CodePush references from your codebase.
API Mapping
Use this table as a quick reference when updating your code:
| CodePush | SwiftPatch |
|---|---|
codePush(options)(App) | withSwiftPatch(App, config) |
codePush.sync() | useSwiftPatch() hook |
codePush.checkForUpdate() | checkForUpdate() |
codePush.getUpdateMetadata() | getCurrentBundle() |
codePush.notifyAppReady() | markMounted() (automatic) |
codePush.restartApp() | restart() |
InstallMode.IMMEDIATE | InstallMode.IMMEDIATE |
InstallMode.ON_NEXT_RESTART | InstallMode.ON_NEXT_RESTART |
InstallMode.ON_NEXT_RESUME | InstallMode.ON_NEXT_RESUME |
CheckFrequency.ON_APP_RESUME | checkOnResume: true |
CheckFrequency.MANUAL | Call checkForUpdate() manually |
appcenter codepush release-react | swiftpatch deploy |