An overview of the

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

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

Specifically, when an application needs to send message to push the message will be sent to apple first by the application server or Google news push server, and then by APNs or FCM (Google news push framework) sent to the equipment, the equipment after the message is received after the system level analysis, finally put forward the message to its application, The whole workflow is shown below.

However, since Google’s service is not stable in mainland China, domestic Android phone vendors usually replace Google’s service with their own push services and customize a set of push standards, which undoubtedly increases the burden of adaptation for developers. Therefore, when dealing with message push on Android, third-party push services such as Aurora, Getui and Umeng are usually used. When companies choose third-party tools, they weigh different scales, so which one to choose as the push service depends on the actual situation.

Although these third-party push service using self-built long connection, unable to enjoy the underlying operating system optimization, but they will all use push service of application sharing push channel, as long as there is an application of using a third party recommendation not killed by the system, can let the message delivered in a timely manner, therefore does not need to worry about the message arrival rate.

Since the functions and access process provided by third-party push service providers are mostly consistent, we can directly use the PLUGIN in THE Flutter project, considering that aurora community and ecology are relatively active, and the PLUGIN was launched earlier in China. The diagram below is the architecture diagram of Aurora push.

Aurora Push, abbreviated as JPush, is a free third-party message push service manufacturer. Around the push service, Aurora has officially launched SDK and plug-ins of many platforms, as shown in the figure below.

Add aurora plugin

The Flutter plugin supports multiple dependencies. There are usually three dependencies: git dependencies, pub.dev dependencies, and local dependencies.

Git dependencies

Open the Flutter project’s Pubspec. yaml configuration file and add the following dependencies.

# Aurora Push plugin
  jpush_flutter:
    Git dependencies
    git:
      Git dependencies
      url: git://github.com/jpush/jpush-flutter-plugin.git
      # branch in git repository
      ref: master
Copy the code

Then, click Packages Get to download the dependencies or load the dependencies directly by using the flutter Packages get command in the terminal command line, as shown in the figure below.

Pub. dev mode dependent

Pub is Google’s official Dart Packages repository, similar to node’s NPM repository and Android’s JCenter repository, where you can find the Packages and plug-ins you need. We can visit the domestic PUB warehouse to search for the plug-ins we need more quickly.

Jpush_flutter: 0.1.0 from jpush_flutter: ^ 0.1.0 fromCopy the code

The difference between the two versions is that the latter will automatically download a higher version, such as 0.1.0, when the version in the PUB repository is upgraded to 0.1.3, then the local dependent version in our project may not be the current set of 0.1.0, but some other version. Of course, you can also use the following methods.

jpush_flutter: any
Copy the code

The difference of the former is that it will load the plugins suitable for the current project environment according to the current project environment. For example, sometimes when we specify the version loading, there will be various conflicts of exceptions. When there is no big difference between several versions and the functions you use, you can consider using this method to solve the problem simply and rudely.

Relying on local

In addition to the above two methods, we can also download the Aurora Push Flutter plugin locally and then rely on it locally. First, download the source code for aurora push Flutter on Github.

# Aurora Push pluginjpush_flutter: path: .. /jpush-flutter-pluginCopy the code

The one used here.. / is a readjustment of the path, of course you can also use the full path of the jpush-fall-plugin folder.

Push the sample

The original configuration

Android Configuration

Since push involves a lot of native configuration, some configuration work needs to be done on native Android and iOS in order for push to work properly. For Android, the configuration is relatively simple. Open the Android /app/build.gradle file and add the following code to the defaultConfig node.

android: {
  ....
  defaultConfig {
    applicationId "Replace it with your app ID.". // NDK is used to specify 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",]}}Copy the code

As shown in the figure below.

IOS platform dependency

For iOS, application configuration is more complicated than that for Android, because iOS push configuration involves application permissions, Apple APNs service and aurora background information association.

Run the project

Once this is done, all the native environments required for aurora push are configured. Next, open the Flutter project using Android Studio and add the initialization JPush code to the initState lifecycle function in 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, // Whether to print debug logs); }Copy the code

Then start the Flutter app and add a push message to the aurora Developer service background. Select the platform to push to and click the “Send Now” button, as shown below.