How Can I Quickly Integrate App Linking of AppGallery Connect into My iOS App?

Search This thread

Mayism

Senior Member
Nov 5, 2020
111
25
github.com
My app has recently needed to use cross-platform sharing links and fortunately App Linking in AppGallery Connect exactly meets my requirements.

Perform the following steps for service integration:
i. Create an app and enable App Linking for the app.
ii. Create a URL prefix.
iii. Integrate the App Linking SDK into the Xcode project.
iv. Create a link of App Linking.
v. Receive and test the link.

1. Creating an App and Enabling App Linking for the App​

Create an app or use an existing app in AppGallery Connect. Click My projects and go to Grow > App Linking, and click Enable now in the displayed page.

0*lYcFZhuWZyyygo2l.png

Go to My projects > Project settings > General information, download the agconnect-services.plist file, and save the file to the directory of your Xcode project.

0*SRgi1X2JmxkIFKCG.png

2. Creating a URL Prefix​

On the displayed App Linking service page, click the URL prefix tab and then click Add URL prefix to create a unique URL prefix.

The system will automatically check uniqueness of your domain name.

0*vrpcky-Vgn2hT4mx.png
0*1UxrI5VdI9J9Hs1q.png

3. Integrating the App Linking SDK into Your Xcode Project​

1. Open the CLI and navigate to the location of the Xcode project.
2. Run the pod init command to create a Podfile.

0*XN1EqmHfwqz9Zjeo.png

3. Open the Podfile and add the pod on which the AppGallery Connect base SDK depends to the Podfile.

Code:
pod 'AGConnectCore'
pod 'AGConnectAppLinking'
0*DHPY-KmiSTTs7WoD.png

4. Run the pod install command to install the pod.
5. Do as follows to initialize the AppGallery Connect SDK: Import the header file <AGConnectCore/AGConnectCore.h> to the AppDelegate.m file of the project,
and add the following code to the application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method:

Code:
#import "AppDelegate.h"
#import <AGConnectCore/AGConnectCore.h>
@implementation AppDelegate
- (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
    // Override point for customization after Application launch.
    [AGCInstance startup];// Initialization
    return YES;
}
0*5uZFrsdc2BJEG3bm.png

4. Creating a Link of App Linking​

You can create a link of App Linking in AppGallery Connect or call an API in your Xcode project.

4.1 Creating a Link of App Linking in AppGallery Connect​

1. On the displayed App Linking service page, click the App Linking tab and create a link as prompted.
0*B1DaTdha6JYsMM4Z.png

2. Complete default deep link configurations. Refer to the following example. Pay attention to the deep link configuration for Android.
0*hnkc1WbxbUxspuY0.png

3. Set Link behavior for Android to Open in app.
0*ikBbvevFFNtXKTQa.png

After the link is successfully created, you can then copy and use it.
0*ieysYjLuiZhLG8Y-.png

4.2 Creating a Link Through Coding​

1. In the following iOS UI layout, add three button controls to create and copy links and four label controls to display the created links.
0*RHlL7qtxH6R6-5fH.png

2. Declare necessary parameters.
0*nyRdSW4sT9L-k4wS.png

3. Create a link.

Here, the iOS deep link is set to agckit://android/detail.
The Android deep link is set to agckit://android/detail.

0*tGlattWGPmeS2V-A.png

4. Copy the long link and short link.
0*2INpqF7l4M6tSLFO.png

Refer to the following example for copying links:

0*Bq1QcxFRzRHGeGiA.png
0*5pc5CtF33CBTnZ_z.png

5. Receiving a Link​

1. To generate an asset verification file for a domain name, set the team ID under Project settings in AppGallery Connect. (The team ID is the value of Membership — Team ID on the Apple developer website.)

0*o6KnsGCW0Ln7UJDD.png

2. After the configuration is complete, an asset verification file is automatically generated for the default domain name. You can view the file at https://your_applinking_url_prefix/apple-app-site-association.

0*OeuEnlIBKjb0P0DX.png

3. Set a custom scheme.

0*iQAAPbB9x7I97HlA.png

4. To set the code for receiving links, open the AppDelegate.m file and add the handleAppLinking method to the system startup method to process received link events.

0*NHp4gaDr5wYCxFhL.png

5. Check whether the received link is a link of App Linking and whether the app can process the link.

0*PhJf9fgeF2qQR28a.png

For a custom scheme link:

Call sharedInstance of App Linking in the application: openURL: options: method to obtain a singleton object, and call openDeepLinkURL of the object to process the received link.

0*UpTxCDE53BQxJ-gl.png

6. Packaging and Testing​

1. Verify the link creation.
Tap CreatLink. A long link and a short link are generated.

0*NrITZt3YarMMqP6J.png

2. Verify the function of starting an app through a link.
Click CopyShortLink and copy the link to the browser. An app can be started when you access the link.

0*6Ar720EJm__6HDgB.png

7. Summary​

Integration is simple. The SDK is small, and links can be shared across Android and iOS. No adaptation is required on different platforms, thereby reducing the workload.
Operations personnel can create links in AppGallery Connect for app promotion, and you can write code in apps to create links in a very convenient process.

For more information, please refer to:
HUAWEI AppGallery Connect App Linking documentation: https://developer.huawei.com/consum...ry-connect-Guides/agc-applinking-introduction
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone