tencent cloud

Feedback

Last updated: 2024-06-13 10:21:45

    Operation step

    Step 1: Integrate message push plugin

    This plugin is known as tencent_cloud_chat_push on pub.dev. You can include it in your pubspec.yaml dependency directory, or run the following command for automatic installation.
    flutter pub add tencent_cloud_chat_push

    Step 2: Push parameter configuration

    iOS
    Android
    Please upload the iOS APNs push certificate obtained during the vendor configuration step to the IM console.
    The IM console will assign a certificate ID for you, as shown in the figure below:
    
    
    
    As early as possible after your application starts, call the TencentCloudChatPush().setApnsCertificateID method to pass in the certificate ID.
    TencentCloudChatPush().setApnsCertificateID(apnsCertificateID: Certificate ID);
    After completing the manufacturer push information on the console, download and add the configuration file to the project. Add the downloaded timpush-configs.json file to the android/app/src/main/assets directory. If the directory does not exist, please create it manually.
    1. Choose to download the configuration file timpush-configs.json
    1. Add to the project
    
    
    
    
    
    
    

    Step 3: Client Code Configuration

    In this step, you'll need to write some native code, such as: Swift, Java, XML, etc.
    Please don't worry, just follow the instructions and copy the code we provide into the specified file.
    iOS
    Android
    You can use Xcode for editing, or you can directly edit in Visual Studio Code or Android Studio.
    Open the ios/Runner/AppDelegate.swift file, paste the following outlined code into it, as shown in the figure. The code is attached after the picture.
    
    import UIKit
    import Flutter
    
    // Add these two import lines
    import TIMPush
    import tencent_cloud_chat_push
    
    // Add `, TIMPushDelegate` to the following line
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate, TIMPushDelegate {
    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    // Add this function
    func offlinePushCertificateID() -> Int32 {
    return TencentCloudChatPushFlutterModal.shared.offlinePushCertificateID();
    }
    
    // Add this function
    func applicationGroupID() -> String {
    return TencentCloudChatPushFlutterModal.shared.applicationGroupID()
    }
    // Add this function
    func onRemoteNotificationReceived(_ notice: String?) -> Bool {
    TencentCloudChatPushPlugin.shared.tryNotifyDartOnNotificationClickEvent(notice)
    return true
    }
    }
    It is recommended to use Android Studio to complete this part of the editing.
    In the same directory as MainActivity under your project's Android path, create a new Application file class, for example, it can be named MyApplication.java.
    If you have already defined an Application class, you can directly reuse it without having to create it again.
    
    Paste the following code into the file, as shown above:
    Replace 'package' with your own, usually Android Studio will generate it automatically; import com.tencent.chat.flutter.push.tencent_cloud_chat_push.application.TencentCloudChatPushApplication; public class MyApplication extends TencentCloudChatPushApplication { @Override public void onCreate() { super.onCreate(); } }
    Note:
    If you have already created your own Application for other purposes, please directly extend TencentCloudChatPushApplication and ensure in the onCreate() function, you call super.onCreate();.
    Open the android/app/src/main/AndroidManifest.xml file, add a specified android:name parameter for the <application> tag, pointing to the newly made custom Application class. As shown in the figure:
    

    Step 4: Client OEM Configuration

    iOS
    Android
    No need to proceed with this step on the iOS side.
    Open the android/app/build.gradle file, at the end, add a dependencies configuration, and as required, include all or part of the following vendor push packages. Only by including the corresponding vendor's push package can you enable that vendor's Native Push Capability.
    The version numbers mentioned below should be consistent with the version number of this Flutter Push Plugin (tencent_cloud_chat_push).
    dependencies { // Huawei
    implementation 'com.tencent.timpush:huawei:${Push Plugin version number}'
    // XiaoMi
    implementation 'com.tencent.timpush:xiaomi:${Push Plugin version number}'
    // vivo
    implementation 'com.tencent.timpush:vivo:${Push Plugin version number}'
    // Honor
    implementation 'com.tencent.timpush:honor:${Push Plugin version number}'
    // Meizu
    implementation 'com.tencent.timpush:meizu:${Push Plugin version number}'
    // Google Firebase Cloud Messaging (Google FCM)
    implementation 'com.tencent.timpush:fcm:${Push Plugin version number}'
    // Choose one of the two below for OPPO
    // For the China Region, choose to integrate this package
    implementation 'com.tencent.timpush:oppo:${Push Plugin version number}'
    // For other regions, choose to integrate this package
    implementation 'com.tencent.timpush:oppo-intl:${Push Plugin version number}' }
    Vivo and Honor Adaptation According to Vivo and Honor Vendor Access Guide, it is necessary to add APPID and APPKEY to the Manifest File.
    Method 1
    Method 2
    // android/app/build.gradle
    
    android {
    ...
    defaultConfig {
    ...
    manifestPlaceholders = [
    "VIVO_APPKEY" : "`APPKEY` of the certificate assigned to your application",
    "VIVO_APPID" : "`APPID` of the certificate assigned to your application",
    "HONOR_APPID" : "`APPID` of the certificate assigned to your application"
    ]
    }
    }
    // android/app/src/main/AndroidManifest.xml
    
    // Vivo begin
    <meta-data tools:replace="android:value"
    android:name="com.vivo.push.api_key"
    android:value="`APPKEY` of the certificate assigned to your application" />
    <meta-data tools:replace="android:value"
    android:name="com.vivo.push.app_id"
    android:value="`APPID` of the certificate assigned to your application" />
    // Vivo end
    
    // Honor begin
    <meta-data tools:replace="android:value"
    android:name="com.hihonor.push.app_id"
    android:value="`APPID` of the certificate assigned to your application" />
    // Honor end
    Adapting to Huawei, Honor, and Google FCM
    Follow the vendor's method to integrate the corresponding plugin and JSON configuration file.
    Note:
    The following adaptation for Honor is only needed for version 7.7.5283 and above.
    1.1 Download the configuration file and add it to the root directory of the project/Android/app.
    Huawei
    HONOR
    Google FCM
    Operation Path
    
    
    
    
    
    
    
    
    
    
    
    
    1.2 Add the following configuration under buildscript -> dependencies in the project-level build.gradle file:
    Gradle 7.1 and above
    Add the following configuration under buildscript -> dependencies in the project-level build.gradle file:
    buildscript {
    dependencies {
    ...
    classpath 'com.huawei.agconnect:agcp:1.6.0.300' classpath 'com.hihonor.mcs:asplugin:2.0.1.300' classpath 'com.google.gms:google-services:4.4.0'
    }
    }
    Add the following repository configuration under buildscript -> repositories and allprojects -> repositories in the project-level settings.gradle file:
    pluginManagementbuildscript {
    repositories {
    gradlePluginPortal() mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for the HMS Core SDK.

    Step 5: Handle the message click callback, and parse the parameters

    Please define a function to receive the push message click callback event.
    Define the function with the following parameters: {required String ext, String? userID, String? groupID}.
    Among them, the ext Field carries the complete ext information specified by the sender. If not specified, a default value is assigned. You can navigate to the corresponding page by parsing this field.
    The userID and groupID fields are automatically attempted by the plugin to parse the ext Json String, retrieving the single chat partner userID and group chat groupID information. If you have not defined the ext Field yourself, and the ext Field is default specified by the SDK or UIKit, then you can use the default parsing provided here. If parsing fails, it will be null.
    You can define a function to receive this callback and navigate to the corresponding session page or your business page accordingly.
    Example below:
    void _onNotificationClicked({required String ext, String? userID, String? groupID}) { print("_onNotificationClicked: $ext, userID: $userID, groupID: $groupID"); if (userID != null || groupID != null) { // Navigate to the corresponding Message Page based on userID or groupID. } else { // Write your own parsing method based on the ext Field and navigate to the corresponding page. } }

    Step 6: Register Push Plugin

    Please register the push plugin immediately after logging into IM and before using other plugins (such as CallKit).
    Invoke the TencentCloudChatPush().registerPush method, passing in a callback function defined for clicks.
    Furthermore, you have the option to also pass in apnsCertificateID for the iOS push certificate ID and androidPushOEMConfig for the Android push vendor configuration. These two configurations should have been specified in previous steps, and if no modification is necessary, they do not need to be passed again.
    TencentCloudChatPush().registerPush(onNotificationClicked: _onNotificationClicked);
    Note:
    If your application requires the use of push plugin for business message notifications , and it does not immediately start and log in to the IM module after launching <3>, or if you need to handle business navigation by obtaining message click callbacks before logging in to the IM module <5>, it is recommended that you call the <7>TencentCloudChatPush().registerOnNotificationClickedEvent</7> method as soon as possible to manually mount the message click callback, so that you can promptly obtain the message parameters.
    In this scenario, you can execute this function before calling TencentCloudChatPush().registerPush and place it as early as possible in the code.
    TencentCloudChatPush().registerOnNotificationClickedEvent(onNotificationClicked: _onNotificationClicked);

    Step 7: Message Push Delivery Statistics

    If you need to collect data on delivery, please complete the setup as follows:
    Huawei
    HONOR
    vivo
    Meizu
    iOS
    
    Receipt Address: https://api.im.qcloud.com/v3/offline_push_report/huawei
    Note:
    Huawei Push Certificate ID <= 11344, using Huawei Push v2 version interface does not support reach and click receipt, please regenerate and update the certificate ID.
    
    Receipt Address: https://api.im.qcloud.com/v3/offline_push_report/honor
    Callback Address Configuration
    Receipt ID Configuration in the IM Console
    
    
    
    Receipt Address: https://api.im.qcloud.com/v3/offline_push_report/vivo
    
    
    
    
    
    Enable Receipt Switch
    Configure Receipt Address
    
    
    
    
    
    
    Receipt Address: https://api.im.qcloud.com/v3/offline_push_report/meizu
    Note:
    After enabling the Receipt Switch, please make sure the Receipt Address is configured correctly. Failing to configure or configuring the wrong address will affect the push feature.
    
    For iOS Push Notification Reach Statistics Configuration, please refer to Statistics Push Arrival Rate.
    No configuration is needed for other supported manufacturers; FCM does not support the push notification statistics feature.
    Congratulations, you have completed the integration of the push plugin. A reminder: After the trial or purchase of the push plugin expires, the push service will automatically stop (including regular message offline push, all-member/Tag push, etc.). To avoid affecting the normal use of your business, please purchase/ renew in advance.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support