Flutter application integrated Aurora push

Time:2021-7-30

summary

In mobile application development, message push can be said to be a very important function. It can remind or wake up users. At the same time, it is also an important means for product operators to achieve operational objectives more efficiently, such as pushing a new commodity or the latest news to users.

In fact, message push is a complex business application scenario spanning five aspects: business server, third-party push service hosting vendor, operating system long connection push service, user terminal and mobile phone application. In the development of native IOS, in order to simplify message push, Apple Push Service (APNs) takes over the message notification requirements of all applications of the system, and any third-party message push needs to be forwarded through the push service. For the native Android platform, it can enable the firebase cloud messaging mechanism provided by Google to achieve a unified push hosting service.

Specifically, when an application needs to send a message push, the message will be sent by the application server to Apple or Google’s message push server, and then sent to the device via APNs or FCM (Google’s message push framework). After receiving the message, the device will complete the analysis through the system layer, and finally forward the message to the application. The whole workflow is shown in the figure below.

Flutter application integrated Aurora push

However, due to the instability of Google services in the mainland, domestic Android mobile phone providers usually replace Google services with their own developed push services and customize a set of push standards, which undoubtedly increases the burden of adaptation for developers. Therefore, when processing message push on Android, third-party push services are usually used, such as Aurora, personal push and Youmeng push. When companies choose third-party tools, due to different scales of trade-offs, which one to choose as a push service has to be determined according to the actual situation.

Although these third-party push services use self built long connections and cannot enjoy the optimization of the underlying operating system, they will share the push channel for all applications using the push service. As long as one application using the third-party push service is not killed by the system, the message can be delivered in time. Therefore, the message arrival rate does not need to be considered.

Since the functions and access processes provided by the third-party push service manufacturers are mostly consistent, considering the relatively active community and ecology of Aurora and the earlier launch of the flutter plug-in in China, we can directly use this plug-in in the flutter project. The following figure is the architecture diagram of Aurora push.
Flutter application integrated Aurora push

Aurora push, jpush for short, is a free third-party message push service provider. Around the push service, Aurora has officially launched SDK and plug-ins for many platforms, as shown in the figure below.

Flutter application integrated Aurora push

Add Aurora plugin

The fluent plug-in supports a variety of dependency modes, usually including git dependency, pub.dev dependency and local dependency.

Dependency via Git

Open the pubspec.yaml configuration file of the fluent project, and add the following dependency code.

#Aurora push plug-in
  jpush_flutter:
    #Git dependency mode
    git:
      #Git dependent address
      url: git://github.com/jpush/jpush-flutter-plugin.git
      #Branches in Git repository
      ref: master

Then, click packages get to download the dependency, or directly use the fluent packages get command on the terminal command line to load the dependency, as shown in the following figure.
Flutter application integrated Aurora push
Loading directly from GitHub through git has a lot to do with your network speed. It is also likely that the loading will not succeed. You need to wait patiently.

Pub.dev mode dependency

Pub is Google’s official dart packages repository, similar to the NPM repository in node and jcenter in Android. We can find the packages and plug-ins we need on it. We can visitDomestic pub warehouseTo search the plug-ins we need faster.
Flutter application integrated Aurora push
Then, configure the pub dependency of Aurora push in the pubspec.yaml file of the shuttle project, as shown below.

jpush_flutter: 0.1.0
jpush_flutter: ^0.1.0

The difference between the two writing methods is that the latter will automatically download a higher version. For example, 0.1.0 is configured here. When the version in the pub warehouse is upgraded to 0.1.3, the locally dependent version in our project is not necessarily the currently set version of 0.1.0, but other versions. Of course, the following methods can be used.

jpush_flutter: any

The difference of the former is that the version plug-ins suitable for the current project environment will be loaded according to the current project environment. For example, sometimes when we specify the version loading, various abnormal conflicts will occur. When the functions in several versions are not much different from those you use, you can consider using this method to solve them simply and roughly.
Flutter application integrated Aurora push

Local dependency

In addition to the above two methods, we can also download the aurora push shuttle plug-in locally and then rely on it locally. First, go to GitHub to download the source code of Aurora push shuttle plug-in.
Flutter application integrated Aurora push
Then unzip the downloaded zip file and put it into a directory. Then configure the local dependency of Aurora push in pubspec.yaml in the shuttle project, as shown below.

#Aurora push plug-in
  jpush_flutter:
    path: ../jpush-flutter-plugin

The.. / used here is the representation of the proofreading path. Of course, you can also use the full path of the jpush fluent plugin folder.
Flutter application integrated Aurora push
There are many ways to rely on Aurora push plug-ins in the shuttle project. After successful dependence, it is shown in the figure below.
Flutter application integrated Aurora push

Push example

Native configuration

Android platform configuration

Because push involves many native configurations, in order to push messages normally, some configuration work needs to be done in native Android and IOS. For the Android platform, the configuration work is relatively simple. Open the Android / APP / build.gradle file, and then add the following code in the defaultconfig node.

android: {
  ....
  defaultConfig {
    Applicationid "replace with your own application ID"
...
//NDK is used for real machine operation and specifies the corresponding chip architecture
    ndk {
    abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',        
    }

    manifestPlaceholders = [
        JPUSH_PKGNAME : applicationId,
        JPUSH_APPKEY : "appkey", 
        JPUSH_CHANNEL : "developer-default",
    ]
  }    
}

As shown in the figure below.
Flutter application integrated Aurora push
Create a push application in the aurora developer platform, and then fill in the parameters required by the build.gradle script, as shown in the figure below.
Flutter application integrated Aurora push
Then, when running the project on the Android phone, you will be prompted with the running gradle task… And go to maven jcenter to download the dependency library and OS library used by the Android platform.
Flutter application integrated Aurora push

IOS platform dependency

For the IOS platform, the application configuration is more cumbersome than the Android platform, because the push configuration of IOS will involve the process of application permissions, apple APNs service and aurora background information association.
Flutter application integrated Aurora push
Then, use Xcode to open the IOS project of the fluent project, and then select [target] → [signing & capabilities] → [capability] → [push notifications] to start the message push function of the application, as shown in the following figure.
Flutter application integrated Aurora push
Then, configure the relevant push authentication of IOS in the aurora developer platform.
Flutter application integrated Aurora push
In the process of applying for a push certificate, the aurora push official website provides more detailed operation steps, which can be applied according to the steps on the official website. Then, upload the requested push Certificate in the aurora developer service background, as shown in the figure below.

Flutter application integrated Aurora push
After the certificate is prepared, run the fluent project on the iPhone, as shown in the figure below.
Flutter application integrated Aurora push

Run project

After completing the above operations, all the native environments required for Aurora push are configured. Next, open the fluent project using Android studio, and add the initialization jpush code in the initstate lifecycle function of the main.dart file, as shown below.

void initState() {
   super.initState();
   JPush jpush = new JPush();
   jpush.setup(
   appKey: "96d7d7e77bee7abd4d568978",
   channel: "flutter_channel",
   production: false,
   Debug: true, // print the debug log
   );
 }

Then, start the fluent application, add a push message in the background of Aurora developer service, select the platform to be pushed, and then click the [send now] button, as shown in the figure below.
Flutter application integrated Aurora push
After the message is pushed successfully, you can see the pushed message on the corresponding mobile device, as shown in the figure below.
Flutter application integrated Aurora push