iOS Setup
Once you've acquired the CodePush 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 the necessary CocoaPods dependencies. - Change bundleUrl on AppDelegate file.
- Swift
- Objective-C
-
Open up the
ios/[ProjectName]/AppDelegate.swiftfile, and add an import statement for the CodePush headers; -
Find the following line of code, which sets the source URL for bridge for production release and replace it with the following line;
import React
import CodePush
override func bundleURL() -> URL? {
#if DEBUG
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
CodePush.bundleURL()
#endif
}
-
Open up the
ios/[ProjectName]/AppDelegate.mfile, and add an import statement for the CodePush headers; -
Find the following line of code, which sets the source URL for bridge for production release and replace it with the following line:
#import "AppDelegate.h"
#import <CodePush/CodePush.h>
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
return [CodePush bundleURL];
#endif
}
- Add the CodePushDeploymentKey key (generated in the create app step) in the file
ios/[ProjectName]/Info.plist
<key>CodePushDeploymentKey</key>
<string>YOUR_IOS_DEPLOYMENT_KEY</string>
- Certifies that your deployment_target is 15.5 or higher in your
ios/Podfilefile.
platform :ios, '15.5'
Code Signing setup (optional)
Starting with CLI version 2.1.0 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 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>