Skip to content

Latest commit

 

History

History
130 lines (90 loc) · 3.47 KB

File metadata and controls

130 lines (90 loc) · 3.47 KB

Native Integration

Android

Touch these files when integrating SrcPush in a bare React Native Android app:

  • android/app/build.gradle
  • android/app/src/main/res/values/strings.xml
  • android/app/src/main/java/.../MainApplication.(kt|java)
  • android/app/src/main/AndroidManifest.xml when the library or app requires metadata flags

android/app/build.gradle

Add the package Gradle helper near the other apply from: lines:

apply from: "../../node_modules/@srcpush/react-native-code-push/android/codepush.gradle"

Prefer placeholders instead of real deployment keys in git:

buildTypes {
    debug {
        resValue "string", "CodePushDeploymentKey", '"YOUR_ANDROID_STAGING_KEY"'
    }
    release {
        resValue "string", "CodePushDeploymentKey", '"YOUR_ANDROID_PRODUCTION_KEY"'
    }
}

If the project already keeps CodePushDeploymentKey in strings.xml, keep a single source of truth. Do not duplicate values across both mechanisms unless the app already depends on that pattern.

strings.xml

Add or preserve these keys:

<string name="CodePushDeploymentKey">YOUR_ANDROID_DEPLOYMENT_KEY</string>
<string name="CodePushServerUrl">https://api.srcpush.com</string>
<string name="CodePushPublicKey">YOUR_PUBLIC_KEY</string>

CodePushServerUrl and CodePushPublicKey are optional unless the backend configuration requires them.

Application class

Import CodePush and override getJSBundleFile() inside the ReactNativeHost:

import com.microsoft.codepush.react.CodePush

override fun getJSBundleFile(): String {
    return CodePush.getJSBundleFile()
}

React Native version changes may alter the exact host class shape. Preserve the project’s current DefaultReactNativeHost or legacy host pattern and only add the override where it belongs.

iOS

Touch these files when integrating SrcPush in a bare React Native iOS app:

  • ios/Podfile
  • ios/<AppTarget>/AppDelegate.mm or AppDelegate.m
  • ios/<AppTarget>/Info.plist

Podfile

Add the pod when required by the project:

pod 'CodePush', :path => '../node_modules/@srcpush/react-native-code-push'

Run pod install after changing pods.

App delegate

Import the header and return the SrcPush bundle in release builds:

#import <CodePush/CodePush.h>

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  #else
    return [CodePush bundleURL];
  #endif
}

If the app already customizes sourceURLForBridge, keep all existing behavior and only replace the release bundle location.

Info.plist

Add placeholders, not secrets:

<key>CodePushDeploymentKey</key>
<string>YOUR_IOS_DEPLOYMENT_KEY</string>
<key>CodePushServerURL</key>
<string>https://api.srcpush.com</string>
<key>CodePushPublicKey</key>
<string>YOUR_PUBLIC_KEY</string>

Do not add ATS exceptions unless the deployment endpoint actually needs them.

JavaScript runtime

Typical wrapper:

import codePush from '@srcpush/react-native-code-push';

const codePushOptions = {
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
  installMode: codePush.InstallMode.ON_NEXT_RESTART,
  mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
  updateDialog: false,
};

export default codePush(codePushOptions)(App);

If the app needs a custom modal or progress UI, call codePush.checkForUpdate() and codePush.sync() manually instead of relying only on the HOC defaults.