Once you've acquired the Source Push plugin, you need to integrate it into the Xcode project of your React Native app and configure it correctly. To do this, take the following steps:
-
Run
cd ios && pod install && cd ..to install all the necessary CocoaPods dependencies. -
Change bundleUrl on AppDelegate file.
If you're using objective-c:
-
Open up the
AppDelegate.mfile, and add an import statement for the Source Push headers:```objective-c #import <CodePush/CodePush.h> ``` -
Find the following line of code, which sets the source URL for bridge for production releases:
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
-
Replace it with this line:
return [CodePush bundleURL];
This change configures your app to always load the most recent version of your app's JS bundle. On the first launch, this will correspond to the file that was compiled with the app. However, after an update has been pushed via Source Push, this will return the location of the most recently installed update.
NOTE: The
bundleURLmethod assumes your app's JS bundle is namedmain.jsbundle. If you have configured your app to use a different file name, simply call thebundleURLForResource:method (which assumes you're using the.jsbundleextension) orbundleURLForResource:withExtension:method instead, in order to overwrite that default behaviorTypically, you're only going to want to use Source Push to resolve your JS bundle location within release builds, and therefore, we recommend using the
DEBUGpre-processor macro to dynamically switch between using the packager server and Source Push, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time.Your
sourceURLForBridgemethod should look like this:- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [CodePush bundleURL]; #endif }
If you're using Swift:
-
Open up the
AppDelegate.swiftfile, and add an import statement for the Source Push headers:import CodePush -
Find the following line of code, which sets the source URL for bridge for production release:
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
-
Replace it with this line:
CodePush.bundleURL()
Your
bundleUrlmethod should look like this:override func bundleURL() -> URL? { #if DEBUG RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") #else CodePush.bundleURL() #endif }
-
-
Add the Deployment key to
Info.plist:To let the Source Push runtime know which deployment it should query for updates against, open your app's
Info.plistfile and add a new entry namedCodePushDeploymentKey, whose value is the key of the deployment you want to configure this app against (like the key for theStagingdeployment for theFooBarapp). You can retrieve this value by runningsrcpush deployment ls <appName> -kin the Source Push CLI (the-kor--displayKeysflag is necessary since keys aren't displayed by default) or take in Source Push UI and copying the value of theKeycolumn which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.In order to effectively make use of the
StagingandProductiondeployments that were created along with your Source Push app, refer to the multi-deployment testing docs below before actually moving your app's usage of Source Push into production.Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using Code-Push options
Source Push plugin makes HTTPS requests to the following domains:
- api.srcpush.com
- blob.srcpush.com
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>api.srcpush.com</key>
<dict><!-- read the ATS Apple Docs for available options --></dict>
</dict>
</dict>
<!-- ...other configs... -->
</dict>
</plist>Before doing anything, please read the docs first.
You can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to relevant Source Push documentation section.
In order to configure Public Key for bundle verification you need to add record in Info.plist with name CodePushPublicKey and string value of public key content. Example:
<plist version="1.0">
<dict>
<!-- ...other configs... -->
<key>CodePushPublicKey</key>
<string>-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANkWYydPuyOumR/sn2agNBVDnzyRpM16NAUpYPGxNgjSEp0etkDNgzzdzyvyl+OsAGBYF3jCxYOXozum+uV5hQECAwEAAQ==
-----END PUBLIC KEY-----</string>
<!-- ...other configs... -->
</dict>
</plist>