flutter 集成极光推送(有图)

话不多说上效果图(效果图为练手项目,不要在意)

 

 

 

极光推送flutter 版github 地址   https://github.com/jpush/jpush-flutter-plugin

极光后台配置此处不再一一赘述。

Android:

在 /android/app/build.gradle 中添加下列代码:

 

flutter 集成极光推送(有图)_第1张图片

 

修改  main.dart

重写  initState 方法。调用下面函数。

flutter 集成极光推送(有图)_第2张图片

Future initPlatformState() async {

String platformVersion;

jpush.getRegistrationID().then((rid) {

print(rid);

});

jpush.setup(

appKey: "114311f50bb78a9fef2e86b1",

channel: "theChannel",

production: false,

debug: true,

);

jpush.applyPushAuthority(new NotificationSettingsIOS(

sound: false,

alert: false,

badge: false));

try {

jpush.addEventHandler(

onReceiveNotification: (Map message) async {

print("flutter onReceiveNotification: $message");

},

onOpenNotification: (Map message) async {

print("flutter onOpenNotification: $message");

},

onReceiveMessage: (Map message) async {

print("flutter onReceiveMessage: $message");

},

);

}

on Exception {

platformVersion = 'Failed to get platform version.';

}

}

可以看到,极光推送已经有相关函数监听。

 

 

 

 

你可能感兴趣的:(混合开发)