React Native ~ Linking React Native Code Push - rohit120582sharma/Documentation GitHub Wiki

iOS Setup - Manual

In Xcode, in Project Navigator (left pane), right-click on the Libraries > Add files to [project name]. Add ./node_modules/react-native-code-push/ios/CodePush.xcodeproj

In Xcode, in Project Navigator (left pane), click on your project (top), then click on your target row and select the Build Phases tab (right pane). In the Link Binary With Libraries section add libCodePush.a

Click the plus sign underneath the Link Binary With Libraries list and select the libz.tbd library underneath the iOS 9.1 node.

In Xcode, in Project Navigator (left pane), click on your project (top), then click on your project row and select the Build Settings tab (right pane). In the Header Search Paths section add $(SRCROOT)/../node_modules/react-native-code-push/ios. Make sure on the right to mark this new path recursive


Open up the AppDelegate.m file, and add an import statement for the CodePush headers:

#import <CodePush/CodePush.h>

Replace the line which loads your JS Bundle from the app binary for production releases:

NSURL *jsCodeLocation;

#ifdef DEBUG
	jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
#else
	jsCodeLocation = [CodePush bundleURL];
#endif

To let the CodePush runtime know which deployment it should query for updates against, open your app's Info.plist file and add a new entry named CodePushDeploymentKey, whose value is the key of the deployment you want to configure this app against (e.g. the key for the Staging deployment for the FooBar app).

<plist version="1.0">
	<dict>
		<!-- ...other configs... -->

		<key>CodePushDeploymentKey</key>
		<string>-----BEGIN PUBLIC KEY-----
		MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANkWYydPuyOumR
		-----END PUBLIC KEY-----</string>

		<!-- ...other configs... -->
	</dict>
</plist>

Optional: HTTP exception domains configuration (iOS)

CodePush plugin makes HTTPS requests to the following domains:

  • codepush.azurewebsites.net
  • codepush.blob.core.windows.net
  • codepushupdates.azureedge.net

If you want to change the default HTTP security configuration for any of these domains, you have to define the NSAppTransportSecurity (ATS) configuration inside your Info.plist file:

<plist version="1.0">
	<dict>
		<!-- ...other configs... -->

		<key>NSAppTransportSecurity</key>
		<dict>
			<key>NSExceptionDomains</key>
			<dict>
				<key>codepush.azurewebsites.net</key>
				<dict><!-- read the ATS Apple Docs for available options --></dict>
			</dict>
		</dict>

		<!-- ...other configs... -->
	</dict>
</plist>


Android Setup - Manual

In android/settings.gradle file, make the following additions:

include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

In android/app/build.gradle file:

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
dependencies {
	...
	implementation project(':react-native-code-push')
}

In /path_to_your_app/android/app/src/main/res/values/strings.xml file, make the following additions:

<resources>
	<string name="app_name">my_app</string>
	<string moduleConfig="true" name="reactNativeCodePush_androidDeploymentKey"></string>
</resources>

WIX React Native Navigation (1.x) applications

No need to change MainActivity.java file, so if you are integrating CodePush to newly created RNN application it might be looking like this:

import com.facebook.react.ReactActivity;
import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {
}

Update the MainApplication.java file to use CodePush via the following changes:

// ...
import com.facebook.react.ReactInstanceManager;

// Add CodePush imports
import com.microsoft.codepush.react.ReactInstanceHolder;
import com.microsoft.codepush.react.CodePush;

public class MainApplication extends NavigationApplication implements ReactInstanceHolder {

	@Override
	public boolean isDebug() {
		// Make sure you are using BuildConfig from your own application
		return BuildConfig.DEBUG;
	}

	protected List<ReactPackage> getPackages() {
		// Add additional packages you require here
		return Arrays.<ReactPackage>asList(
			new CodePush("deployment-key-here", getApplicationContext(), BuildConfig.DEBUG)
		);
	}

	@Override
	public List<ReactPackage> createAdditionalReactPackages() {
		return getPackages();
	}

	@Override
	public String getJSBundleFile() {
		// Override default getJSBundleFile method with the one CodePush is providing
		return CodePush.getJSBundleFile();
	}

	@Override
	public String getJSMainModuleName() {
		return "index";
	}

	@Override
	public ReactInstanceManager getReactInstanceManager() {
		// CodePush must be told how to find React Native instance
		return getReactNativeHost().getReactInstanceManager();
	}
}

⚠️ **GitHub.com Fallback** ⚠️