How Can I Quickly Integrate App Linking of AppGallery Connect into My iOS App?
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.
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.
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.
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.
3. Open the Podfile and add the pod on which the AppGallery Connect base SDK depends to the Podfile.
pod 'AGConnectCore'
pod 'AGConnectAppLinking'
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:
#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;
}
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.
2. Complete default deep link configurations. Refer to the following example. Pay attention to the deep link configuration for Android.
3. Set Link behavior for Android to Open in app.
After the link is successfully created, you can then copy and use it.
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.
2. Declare necessary parameters.
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.
4. Copy the long link and short link.
Refer to the following example for copying links:
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.)
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.
3. Set a custom scheme.
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.
5. Check whether the received link is a link of App Linking and whether the app can process the link.
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.
6. Packaging and Testing
1. Verify the link creation.
Tap CreatLink. A long link and a short link are generated.
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.
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/consumer/en/doc/development/AppGallery-connect-Guides/agc-applinking-introduction