Overview
You can use App Messaging of AppGallery Connect to send relevant messages to target users actively using your app to encourage them to use key app functions. For example, you can send in-app messages to encourage users to subscribe to certain products, provide hints to a game level, or recommend promotions of a restaurant. App Messaging even allows you to customize how your messages look and the way they will be sent, and define events for triggering message sending to your users when you want to engage your users in your app's activities.
What You Will Create
In this codelab, you will build an app that integrates App Messaging and is able to display messages in different languages created in AppGallery Connect based on the system language.
What You Will Learn
- Integrate App Messaging.
- Create and configure messages in different languages in AppGallery Connect.
Development Environment and Skill Requirements
- A Mac with Xcode 11 or later installed
- CocoaPods 1.10.0 or later installed
- A HUAWEI ID, whose identity has been verified
Device Requirements
An iPhone or a simulator for testing
To integrate App Messaging, you need to complete the following preparations:
- Create an app in AppGallery Connect.
- Create an iOS project.
- Integrate the SDK into your Xcode project.
For details, please refer to Integration Preparations.
You need to register as a developer first to complete the operations above.
Procedure
- Sign in to AppGallery Connect and click My projects. Click your project card, and select an app for which you want to enable App Messaging.
- Go to Grow > App Messaging. If this is your first time using App Messaging, click Use now.

You can use CocoaPods to integrate the App Messaging SDK in Xcode.
- Sign in to AppGallery Connect and click My projects.
- Click your project card and select an app for SDK integration from the app drop-down list on the top.
- Go to Project settings > General information. In the App information area, download the agconnect-services.plist file.
- Copy the agconnect-services.plist file to the project.

- Open the CLI and navigate to the location of the Xcode project. Then, create a Podfile. Skip this step if a Podfile already exists.
cd project-directory
pod init
- Edit the Podfile to add the pod ‘AGConnectAppMessaging' dependency.
target 'AGC-AppMessaging-1' do
pod 'AGConnectAppMessaging'
end
- Install the pod and open the .xcworkspace file to view the project.
pod install
The following figure shows the result after installation.

No special layout is required for the codelab. Use the default layout.

- Go to Grow > App Messaging. On the displayed page, click New.

- Enter the message name and description.

- Set the style and content. In this codelab, create a banner message. Set the message title and body in English. Set other information as required, and click Next.

- Specify target users, set the default condition as sending messages by app, and select the package name of the current app. In this codelab, messages in different languages are needed, so you can click New condition to select Language as another condition.

- Set the sending time as follows. The settings mean that the message will be displayed when your app runs in the foreground or is launched.

- Use default conversion event settings and click Publish in the upper right corner.

- Create another message in the same way, set its title and body in Chinese, and set the target language to Simplified Chinese.
Import AGConnectCore and AGConnectAppMessaging to the AppDelegate class of the app, and call AGCInstance.startUp in the didFinishLaunchingWithOptions method for initialization.
import AGConnectCore
import AGConnectAppMessaging
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AGCInstance.startUp()
return true
}
- Set the language of your mobile phone or simulator to simplified Chinese. Run Xcode and install your app on a test device. After the app is started, a message in Chinese is displayed.

- Set your device language to English. Delete your app from the mobile phone or simulator, and re-install and open the app. A message in English is displayed.

Well done. You have successfully built an app that integrates App Messaging of AppGallery Connect, learned how to integrate the App Messaging SDK, and create and test new messages in AppGallery Connect.
API Reference
Sample code