|
1 | | -# AGConnect Cordova Remoteconfig Demo |
| 1 | +# AGC RemoteConfig Cordova Demo |
2 | 2 |
|
3 | | -`In the root directory, perform the following operations:` |
| 3 | +## Contents |
4 | 4 |
|
5 | | -`Step 1: Run the following command to install the NPM dependency` |
6 | | -`$ npm install` |
| 5 | +- [1. Introduction](#1-introduction) |
| 6 | +- [2. Installation Guide](#2-installation-guide) |
| 7 | + - [2.1. Creating a Project in AppGallery Connect](#21-creating-a-project-in-appgallery-connect) |
| 8 | + - [2.2. Obtaining agconnect-services.json and agconnect-services.plist](#22-obtaining-agconnect-servicesjson-and-agconnect-servicesplist) |
| 9 | + - [2.3. Enabling RemoteConfig Service](#24-enabling-RemoteConfig-service) |
| 10 | + - [2.4. Cordova](#26-cordova) |
| 11 | + - [2.4.1. iOS App Development](#261-ios-app-development) |
| 12 | + - [2.4.2. Android App Development](#262-android-app-development) |
| 13 | +- [3. Method Definitions](#3-method-definitions) |
| 14 | +- [4. Configuration and Description](#4-configuration-and-description) |
| 15 | +- [5. Licensing and Terms](#5-licensing-and-terms) |
7 | 16 |
|
8 | | -`Step 2: Run the following command to create the corresponding platform code` |
9 | | -`$ cordova platform add ios/android` |
| 17 | +--- |
10 | 18 |
|
11 | | -`Step 3: Run the following command to download and install the AGC remoteconfig plugin` |
12 | | -`$ cordova plugin add @cordova-plugin-agconnect/remoteconfig --save` |
| 19 | +## 1. Introduction |
13 | 20 |
|
14 | | -`Step 4: Put the corresponding agconnect-services.json/agconnect-services.plist into the appropriate directory` |
| 21 | +This demo application demonstrates the usage of AGC Cloud Functions Cordova plugin. |
15 | 22 |
|
16 | | -`Step 5: Change the package name in the config.xml file to the package name in the agconnect-services.json/agconnect-services.plist file` |
| 23 | +--- |
17 | 24 |
|
18 | | -`Step 6: Add the agcp-plto the corresponding bulid.gradle(only Android)` |
| 25 | +## 2. Installation Guide |
19 | 26 |
|
20 | | - `apply plugin: 'com.huawei.agconnect'` |
| 27 | +Before you get started, you must register as a HUAWEI Developer and complete identity verification on the [HUAWEI Developer](https://developer.huawei.com/consumer/en/) website. For details, please refer to [Register a HUAWEI ID](https://developer.huawei.com/consumer/en/doc/10104). |
21 | 28 |
|
| 29 | +### 2.1. Creating a Project in AppGallery Connect |
| 30 | + |
| 31 | +Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps: |
| 32 | + |
| 33 | +1. Sign in to [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html) and select **My projects**. |
| 34 | +2. Select your project from the project list or create a new one by clicking the **Add Project** button. |
| 35 | +3. Go to **Project settings** > **General information**, and click **Add app**. |
| 36 | + If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click **Add app**. |
| 37 | +4. On the **Add app** page, enter the app information, and click **OK**. |
| 38 | + |
| 39 | +### 2.2. Obtaining agconnect-services.json and agconnect-services.plist |
| 40 | + |
| 41 | +1. Sign in to [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html) and select your project from **My Projects**. Then go to **Project settings** > **General information**. In the **App information** field, |
| 42 | + |
| 43 | + - If platform is Android, click **agconnect-services.json** button to download the configuration file. |
| 44 | + - If platform is iOS, click **agconnect-services.plist** button to download the configuration file. |
| 45 | + |
| 46 | +### 2.3. Enabling RemoteConfig Service |
| 47 | + |
| 48 | +1. In [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html), find your project, and click the app for which you want to use cloud functions. |
| 49 | + |
| 50 | +2. Select **Grow** and **Remote Config** on the left menu and click **Enable now**. |
| 51 | + |
| 52 | +### 2.4. Cordova |
| 53 | + |
| 54 | +1. Install Cordova CLI. |
| 55 | + |
| 56 | + ```bash |
| 57 | + npm install -g cordova |
| 58 | + ``` |
| 59 | + |
| 60 | +2. Create a new Cordova project or use existing Cordova project. |
| 61 | + |
| 62 | + - To create new Cordova project, you can use **`cordova create path [id [name [config]]] [options]`** command. For more details please follow [CLI Reference - Apache Cordova](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html#cordova-create-command). |
| 63 | + |
| 64 | +3. Update the widget **`id`** property which is specified in the **`config.xml`** file. It must be same with **client > package_name** value of the **`agconnect-services.json`** and **`agconnect-services.plist`** files. |
| 65 | + |
| 66 | +4. Update the '<set_triggerIdentifier>' parameter which is specified in the **`<project_root>/www/js/index.js`** file. |
| 67 | + |
| 68 | +5. Check preference in your Cordova project config.xml. |
| 69 | + |
| 70 | + ```xml |
| 71 | + <!--platform iOS--> |
| 72 | + <preference name="deployment-target" value="11.0" /> |
| 73 | + <preference name="SwiftVersion" value="5" /> |
| 74 | + ``` |
| 75 | + |
| 76 | +6. Add the **Android** or **iOS** platform to the project if haven't done before. |
| 77 | + |
| 78 | + ```bash |
| 79 | + cordova platform add android |
| 80 | + ``` |
| 81 | + |
| 82 | + ```bash |
| 83 | + cordova platform add ios |
| 84 | + ``` |
| 85 | + |
| 86 | +7. Install `AGC RemoteConfig Cordova Plugin` to the project. |
| 87 | + |
| 88 | +- Run the following command in the root directory of your project to install it through **npm**. |
| 89 | + |
| 90 | +```bash |
| 91 | +cordova plugin add @cordova-plugin-agconnect/remoteconfig |
| 92 | +``` |
| 93 | + |
| 94 | +#### 2.6.1. iOS App Development |
| 95 | + |
| 96 | +1. Add **`agconnect-services.plist`** file to the app's root directory of your Xcode project. |
| 97 | + |
| 98 | +2. Run the application. |
| 99 | + |
| 100 | +```bash |
| 101 | +cordova run ios --device |
| 102 | +``` |
| 103 | + |
| 104 | +#### 2.6.2. Android App Development |
| 105 | + |
| 106 | +1. Copy **`agconnect-services.json`** file to **`<project_root>/platforms/android/app`** directory your Android project. |
| 107 | + |
| 108 | +2. Run the application. |
| 109 | + |
| 110 | + ```bash |
| 111 | + cordova run android --device |
| 112 | + ``` |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 3. Method Definitions |
| 117 | + |
| 118 | +#### Public Method Summary |
| 119 | + |
| 120 | +| Method | Return Type | Description | |
| 121 | +| ---------------- | ----------- | ------------------------------------------------------------ | |
| 122 | +| applyDefault | void | Setting Local Default Parameters | |
| 123 | +| applyLastFetched | void | Make the latest configuration obtained from the cloud take effect. | |
| 124 | +| fetch | void | Obtain the latest configuration data from the cloud. | |
| 125 | +| getValue | void | Returns the value of the string type corresponding to the key | |
| 126 | +| getSource | void | Returns the data source corresponding to the key | |
| 127 | +| getMergedAll | void | Returns all values after the default value and cloud value are combined | |
| 128 | +| clearAll | void | Clears all cached data, including the data pulled from the cloud and the transferred default values | |
| 129 | +| setDeveloperMode | void | Set the developer mode.(This API is applicable only to the Android platform) | |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## 4. Configuration and Description |
| 134 | + |
| 135 | +No. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## 6. Licensing and Terms |
| 140 | + |
| 141 | +AGC Cloud Functions Cordova Plugin is licensed under the [Apache 2.0 license](LICENCE). |
0 commit comments