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:
Once the plugin has been downloaded, run npx react-native autolink-windows
in your application's root directory to automatically add the CodePush c++ project to your application's windows solution file.
-
Replace the following files located at
windows/<app name>
with those in the CodePushDemoAppCpp example app in this repo found atExamples/CodePushDemoAppCpp/windows/CodePushDemoAppCpp
:- app.h
- app.cpp
- app.xaml
-
In the above files, replace any occurance of
CodePushDemoAppCpp
with the name of your application -
Enter your application's app version and release channel public ID to the
configMap
object at the top of your app'sOnLaunched
method inApp.cpp
:
...
void App::OnLaunched(activation::LaunchActivatedEventArgs const& e)
{
winrt::Microsoft::CodePush::ReactNative::CodePushConfig::SetHost(Host());
auto configMap{ winrt::single_threaded_map<hstring, hstring>() };
configMap.Insert(L"appVersion", L"1.0.0");
configMap.Insert(L"releaseChannelPublicId", L"<app release channel public id>");
winrt::Microsoft::CodePush::ReactNative::CodePushConfig::Init(configMap);
...
}
...
-
add name space
Microsoft.CodePush
toApp.xaml.cs
-
add app version and release channel public ID to
configMap
at the start of your app'sOnLaunched
method inApp.xaml.cs
.
using Microsoft.CodePush;
...
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Microsoft.CodePush.ReactNative.CodePushConfig.SetHost(Host);
IDictionary<string, string> configMap = new Dictionary<string, string>();
configMap.Add("appVersion", "1.0.0");
configMap.Add("releaseChannelPublicId", "release channel public id");
Microsoft.CodePush.ReactNative.CodePushConfig.Init(configMap);
...
}
...