mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-19 19:39:54 +08:00
In react-native-windows v0.50+, we added ReactNativeHost, which has better support for running React Native in the background as well as embedding React Native in other controls besides XAML Pages.
66 lines
2.7 KiB
Markdown
66 lines
2.7 KiB
Markdown
## Windows Setup
|
|
|
|
Once you've acquired the CodePush plugin, you need to integrate it into the Visual Studio project of your React Native app and configure it correctly. To do this, take the following steps:
|
|
|
|
### Plugin Installation (Windows)
|
|
|
|
1. Open the Visual Studio solution located at `windows\<AppName>\<AppName>.sln` within your app
|
|
|
|
2. Right-click the solution node in the `Solution Explorer` window and select the `Add -> Existing Project...` menu item
|
|
|
|

|
|
|
|
3. Browse to the `node_modules\react-native-code-push\windows` directory, select the `CodePush.csproj` file and click `OK`
|
|
|
|
4. Back in the `Solution Explorer`, right-click the project node that is named after your app, and select the `Add -> Reference...` menu item
|
|
|
|

|
|
|
|
5. Select the `Projects` tab on the left hand side, check the `CodePush` item and then click `OK`
|
|
|
|

|
|
|
|
### Plugin Configuration (Windows)
|
|
|
|
After installing the plugin, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this, update the `MainReactNativeHost.cs` file to use CodePush via the following changes:
|
|
|
|
```c#
|
|
...
|
|
// 1. Import the CodePush namespace
|
|
using CodePush.ReactNative;
|
|
...
|
|
class MainReactNativeHost : ReactNativeHost
|
|
{
|
|
// 2. Declare a private instance variable for the CodePushModule instance.
|
|
private CodePushReactPackage codePushReactPackage;
|
|
|
|
// 3. Update the JavaScriptBundleFile property to initalize the CodePush runtime,
|
|
// specifying the right deployment key, then use it to return the bundle URL from
|
|
// CodePush instead of statically from the binary. If you don't already have your
|
|
// deployment key, you can run "code-push deployment ls <appName> -k" to retrieve it.
|
|
protected override string JavaScriptBundleFile
|
|
{
|
|
get
|
|
{
|
|
codePushReactPackage = new CodePushReactPackage("deployment-key-here", this);
|
|
return codePushReactPackage.GetJavaScriptBundleFile();
|
|
}
|
|
}
|
|
|
|
// 4. Add the codePushReactPackage instance to the list of existing packages.
|
|
protected override List<IReactPackage> Packages
|
|
{
|
|
get
|
|
{
|
|
return new List<IReactPackage>
|
|
{
|
|
new MainReactPackage(),
|
|
...
|
|
codePushReactPackage
|
|
};
|
|
}
|
|
}
|
|
...
|
|
}
|
|
```
|