- AGC AppLinking Cordova Demo
This demo application demonstrates the usage of AGC AppLinking Cordova plugin.
Before you get started, you must register as a HUAWEI Developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:
- Sign in to AppGallery Connect and select My projects.
- Select your project from the project list or create a new one by clicking the Add Project button.
- Go to Project settings > General information, and click Add app.
- 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.
- On the Add app page, select platform Android or iOS and then enter the app information, and click OK.
- To use HUAWEI App Linking, you need to enable the App Linking service first and also create App Linking URL Prefix. For more information, please refer to Enabling the App Linking Service.
- Sign in to AppGallery Connect and select your project from My Projects. Then go to Project settings > General information. In the App information field,
- If platform is Android, click agconnect-services.json button to download the configuration file.
- If platform is iOS, click agconnect-services.plist button to download the configuration file.
-
Install Cordova CLI.
npm install -g cordova
-
Create a new Cordova project or use existing Cordova project.
- 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.
- To create new Cordova project, you can use
-
Update the widget
id
property which is specified in theconfig.xml
file. It must be same with client > package_name value of theagconnect-services.json
andagconnect-services.plist
files. -
Add the Android or iOS platform to the project if haven't done before.
cordova platform add android
cordova platform add ios
-
Install
AGC AppLinking plugin
to the project.- Run the following command in the root directory of your project to install it through npm.
cordova plugin add @cordova-plugin-agconnect/applinking
-
Copy
agconnect-services.plist
file to the app's root directory of your Xcode project. -
In an iOS app, when a user taps a link of App Linking, the link can be redirected in universal link or custom scheme mode.
-
Configuring a Universal Link: A user can be seamlessly redirected to the in-app content after tapping a universal link in iOS 9 and later versions. You only need to complete the following simple configuration to implement link redirection in iOS apps in universal link mode
- Generate an asset verification file of the domain. Sign in to AppGallery Connect, select your app, go to Project settings > General information > App information, and Team ID to set a team ID in the App Store. After the configuration is complete, AppGallery Connect will generate an asset verification file for the default domain.
- After the asset verification file is generated, you can view it at https://your_applinking_url_prefix/apple-app-site-association. your_applinking_url_prefix is the domain name you applied for in AppGallery Connect.
- Declare the domain name associated with your iOS app. On the Signing & Capabilities tab page of your Xcode project, enable the Associated Domains function, and add a domain name to be supported, in applinks:your_applinking_url_prefix format. your_applinking_url_prefix is the domain name you applied for in AppGallery Connect.
-
Configuring a Custom Scheme: If you want a link to be opened in custom scheme mode in your iOS app, you need to set a custom scheme in the iOS deep link and set URL Schemes under URL Types on the Info tab page of your Xcode project.
-
Run the application.
cordova run ios --device
-
Copy
agconnect-services.json
file to<project_root>/platforms/android/app
directory your Android project. -
To use deep links to receive data, you need to add the following configuration to the activity for processing links. Set android:host to the domain name in the deepLink and android:scheme to the custom scheme. When a user taps a link containing this deep link, your app uses this activity to process the link.
<!-- AndroidManifest.xml. /manifest/application/activity--> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Add the custom domain name and scheme --> <data android:host="<DeepLink_Host>" android:scheme="https" /> </intent-filter>
-
Set Android launch mode in your Cordova project config.xml
<preference name="AndroidLaunchMode" value="standard" />
-
Run the application.
cordova run android --device
Method Name | Defination |
---|---|
buildShortLink(args: AppLinkingWithInfo) | This method is called to obtain a short link of App Linking with info in asynchronous mode. |
buildLongLink(args: AppLinkingWithInfo) | This method is called to obtain a long link of App Linking with info in asynchronous mode. |
addListener() | This method is called to obtain the ResolvedLinkDataResult from the asynchronous execution result, and parse the data, for example, deep links, passed through links of App Linking. |
copyShortLink() | This method is called to copy shortLink of AppLinking to clipboard. |
copyTestUrl() | This method is called to copy testURL of AppLinking to clipboard. |
copyLongLink() | This method is called to copy longLink of AppLinking to clipboard. |
- Sign in to AppGallery Connect and click My projects.
- Find your project from the project list and click the app for which you need to enable App Linking on the project card.
- Go to Growing > App Linking. On the App Linking page that is displayed, click Enable now.
- A URL prefix is a URL contained in a link. To uniquely identify the URL prefix, you need to prefix the free domain name (for example, drcn.agconnect.link) provided by AppGallery Connect with a string
- Sign in to AppGallery Connect and click My projects.
- Find your project from the project list and click the app for which you need to create a link of App Linking on the project card.
- Go to Growing > App Linking and click the URL prefix tab.
- Click Add URL prefix and set a unique URL prefix, which can contain only lowercase letters and digits.
- Click Next. A message is displayed, indicating that the URL has been verified.
To use analytics feature,
-
Navigate into your <root_directory>/platforms/android/app/build.gradle and add build dependencies in the dependencies section.
dependencies { implementation 'com.huawei.hms:hianalytics:5.1.0.301' }
-
Navigate into your <root_directory>/platforms/ios file and edit the Podfile file to add the pod dependency 'HiAnalytics'
-
Example Podfile file:
# Pods for AGCAppLinkingDemo pod 'HiAnalytics'
-
Run pod install to install the pods.
$ pod install
-
Initialize the Analytics SDK using the config API in AppDelegate in iOS platform.
Sample code for initialization in AppDelegate.m:
#import "AppDelegate.h" #import <HiAnalytics/HiAnalytics.h> @implementation AppDelegate ... // Customize the service logic after app launch. - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { self.viewController = [[MainViewController alloc] init]; // Initialize the Analytics SDK. [HiAnalytics config]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } ... @end
For further information please refer to Analytics Kit Service Guide.
-
AGC AppLinking Kit Cordova Plugin is licensed under the Apache 2.0 license.