话不多说上效果图(效果图为练手项目,不要在意)
极光推送flutter 版github 地址 https://github.com/jpush/jpush-flutter-plugin
极光后台配置此处不再一一赘述。
Android:
在 /android/app/build.gradle
中添加下列代码:
修改 main.dart
重写 initState 方法。调用下面函数。
Future<void> 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<String, dynamic> message) async {
print("flutter onReceiveNotification: $message");
},
onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message");
},
onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message");
},
);
}
on Exception {
platformVersion = 'Failed to get platform version.';
}
}
可以看到,极光推送已经有相关函数监听。