It’s time to recommend good plugins again. You can’t avoid using push when developing an APP. For example, a new product or the latest sports news will be pushed to users in real time.

Compared with several platforms, it seems that Aurora has the Flutter plugin, so I tried it out and recorded the whole development process of the push feature.

When it comes to “push”, there is a push side and a receive side, and the receiving side includes Android side and iOS side.

demo

Introducing plug-ins:

Flutter_jpush: ^ 0.0.4Copy the code

Add initialization code to main.dart:

void _initJPush() async {
  await FlutterJPush.startup();
  print("Jpush initialized successfully");

  / / get registrationID
  var registrationID =await FlutterJPush.getRegistrationID();
  print(registrationID);
  
  // Register to receive and open Notification()
  _initNotification();
}

void _initNotification() async {
  FlutterJPush.addReceiveNotificationListener(
    (JPushNotification notification) {
      print("Received push notifications: $Notification"); }); FlutterJPush.addReceiveOpenNotificationListener( (JPushNotification notification) {print("$notification enabled"); }); }Copy the code

Android configuration

Create the application in the background of aurora, generate information such as appkey, Android configuration is easy to say, add the package name.

In the Android project build.gradle code, add configuration information:

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.*.*"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [
            JPUSH_PKGNAME : applicationId,
            JPUSH_APPKEY : "* * * *"// The package name registered on aurora corresponds to appkey.jpush_channel:"developer-default"]},Copy the code

All right, let’s write a message notification in the background of the aurora, see what happens.

When the APP is open, run the log command, and we can see “push notifications received” :

At the same time, we get this notification push notification on the notification bar:

Open the notification, enforce a “addReceiveOpenNotificationListener”

It’s as simple as that.

IOS configuration

How to apply for the certificate and sign, specific see aurora: docs. Jiguang. Cn/jpush/clien…

First open “Push Notifications” in Xcode

In the “iOS” project, add the aurora configuration information:

increase#include "FlutterJPushPlugin.h"Increasing [self startupJPush: launchOptions appKey: @"Your key" channel:@"Your channel."IsProduction: whether to produce the version];Copy the code

After configuration, the dart side will use the same code as above, again using the aurora background, and push a test notification to see what happens:

When this notification is opened, print is also executed:

Server Programming Push

As long as the message can reach the client, then the specific use of the client, or open the client to jump to a specific page, these work is easy to say, there is no need to expand here.

The rest is the background interface push notifications, you can’t always do push in the “aurora” background!

So we need the access that Aurora provides.

Aurora provides a multi-language server SDK, which basically meets our integration needs.

Let me talk briefly about integration, using Laravel as an example.

1. Add jpush dependencies to the composer.

"jpush/jpush": "^ 3.5"
Copy the code

2. Write a demo command line push service:

Artisan::command('jpush'.function () {
    $client = new \JPush\Client($app_key.$master_secret);
})->describe('jpush');
Copy the code

3. Try sending a notification:

$client->push()
    ->setPlatform('all')
    ->addAllAudience()
    ->setNotificationAlert('Hello aurora Push')
    ->send();
Copy the code

PHP artisan jpush PHP artisan jpush

Okey, so far, is a simple example of a Push process from the server to the client.

Note: Server SDK reference

Github.com/jpush/jpush…

conclusion

If you know how to incorporate the native Android and iOS widgets into the Flutter, use Aurora Push. You can also write the official Flutter plugin without needing it.

On the other hand, using the official Flutter plugin and the integrated documentation allowed us to quickly implement push notifications, allowing us to focus more on our product logic and functionality.