This topic describes how to use the Mobile Push demo to quickly try the Mobile Push feature.
Create an application
Log on to the EMAS console. Create and open a project, and then click Add Application. Enter an application name and package name to create the application.
Select the application. In the Basic Information section, obtain the AppKey, AppSecret, and PackageName.
If you want to use the push service for an iOS application, you must configure authentication in the Mobile Push console. For more information, see APNs Authentication Configuration.
Android
Download the demo project
For the official Android demo, see Mobile Push Android Demo.
Configure the app information
1. Import the project
Download the sample project and import it using Android Studio.
2. Configure the project
To run the demo application, you must configure your AppKey and AppSecret in the demo project.
Configure your application information in the AndroidManifest.xml file.
<meta-data android:name="com.alibaba.app.appkey" android:value="********"/> <!-- Enter the AppKey of the application that you created in EMAS. --> <meta-data android:name="com.alibaba.app.appsecret" android:value="********"/> <!-- Enter the AppSecret of the application that you created in EMAS. -->In the build.gradle file, change the applicationId to the PackageName that you specified when you created the application in EMAS.
android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "********" // Enter the package name of your app. minSdkVersion 11 targetSdkVersion 23 versionCode 1 versionName "1.0" } ...... }
Run the application
If the program compiles and the MainApplication.initCloudChannel method prints a log similar to the following, the integration is successful.
08-23 11:30:02.741 25116-25116/cloud.aliyun.test I/Init: init cloudchannel success
Install the compiled demo application on a mobile phone and open it.
The demo has the Mobile Push software development kit (SDK) integrated. However, we recommend that you read the relevant SDK document. For more information, see Android SDK Integration.
If you encounter problems when you integrate Mobile Push with your own application, you can compare your configuration with the demo's configuration.
iOS
Download the demo project
For the official iOS demo, see Mobile Push iOS Demo.
Configure the app information
1. Import the project
Download the sample project and import it using Xcode.
2. Configure the project
1. Change the Bundle Identifier. You must change it for mpush_ios_demo, mpush_service_extension, and mpush_content_extension.
2. Change the signing certificate. You must change it for mpush_ios_demo, mpush_service_extension, and mpush_content_extension.
3. Configure your AppKey and AppSecret.
static NSString *const testAppKey = @"******";
static NSString *const testAppSecret = @"******";
// Initialize the SDK.
[CloudPushSDK asyncInit:testAppKey appSecret:testAppSecret callback:^(CloudPushCallbackResult *res) {
if (res.success) {
NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
} else {
NSLog(@"Push SDK init failed, error: %@", res.error);
}
}];
Run the application
Check the SDK initialization callback result to verify that the initialization was successful.
if (res.success) {
NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
} else {
NSLog(@"Push SDK init failed, error: %@", res.error);
}
After the application runs successfully, you can view the demo application interface.
The demo has the Mobile Push SDK integrated. However, we recommend that you read the relevant SDK document. For more information, see iOS SDK Configuration.
If you encounter problems when you integrate Mobile Push with your own application, you can compare your configuration with the demo's configuration.
HarmonyOS
Download the demo project
For the official HarmonyOS demo, see Mobile Push HarmonyOS Demo.
Configure the app information
1. Import the project
Download the sample project and import it using DevEco Studio.
2. Configure the project
1. In the ./entry/oh-package.json5 file of the demo project, set the latest version number. For more information, see HarmonyOS SDK Release Notes.
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
"@aliyun/push": "1.1.0", // The demo uses version 1.1.0 as an example. Check the official Alibaba Cloud documentation for the latest version.
}
}
2. In the ./entry/src/main/ets/common/Constants.ets file of the demo project, configure your AppKey and AppSecret.
export const AppKey = 'Enter the AppKey of the application created on the EMAS platform'
export const AppSecret = 'Enter the AppSecret of the application created on the EMAS platform'
3. Create a HarmonyOS application in AppGallery Connect.
Create an application in AppGallery Connect. The package name of the application must be the same as the package name of the application that you created on the EMAS platform. For more information, see HarmonyOS Application Development Preparation.
Create and download the service account key for the push service API. For more information, see Service Account Key. Then, configure the HarmonyOS vendor channel on the EMAS platform. For more information, see Configure the Account Key File.
In AppGallery Connect, view the package name of the application in "My projects". Replace the package name in the ./AppScope/app.json5 file of the demo project with your application's package name.
{
"app": {
"bundleName": "Your application package name",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
Run the application
Application signing: DevEco Studio provides an automatic signing solution to help developers debug efficiently. You can also manually sign the application or service.
For more information, see Application and Service Signing.
Run the application:
After the application runs, the demo application interface opens.
The demo has the Mobile Push SDK integrated. However, we recommend that you read the relevant SDK document. For more information, see HarmonyOS SDK Integration.
If you encounter problems when you integrate Mobile Push with your own application, you can compare your configuration with the demo's configuration.
Push from the console
Log on to the EMAS console.
In the top navigation bar, select User Growth.
In the navigation pane on the left, expand the drop-down list next to Mobile Push and click Create Task - Push Notification.
Enter a Notification Title and Notification Body, and then click Push Notification.
View the push notification on your mobile phone.
What to do next
The Mobile Push demo provides only basic push features. To integrate it into a real project or use more advanced features, see the Developer Guide.
Contact us
If you encounter any problems, see Technical Support to contact us.