diff --git a/android/app/build.gradle b/android/app/build.gradle index 4643b6f..1b70884 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -46,6 +46,11 @@ android { applicationId "com.akucommunity.aku_community_manager" minSdkVersion 21 targetSdkVersion 29 + manifestPlaceholders = [ + JPUSH_PKGNAME : applicationId, + JPUSH_APPKEY : "99067fe33fa04aad88c3acac", //极光开发平台上注册的包名对应的appkey. + JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. + ] versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/lib/main.dart b/lib/main.dart index 8539d68..744e422 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,12 +11,34 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:get/get.dart'; +import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:provider/provider.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await AmapCore.init(''); await AmapLocation.instance.init(iosKey: ''); + JPush jpush = new JPush(); + 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"); + }, + ); + jpush.setup( + appKey: "99067fe33fa04aad88c3acac", + channel: "developer-default", + production: false, + debug: true, // 设置是否打印 debug 日志 + ); runApp(MyApp()); } @@ -34,7 +56,7 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider(create: (context) => OutdoorProvider()), ChangeNotifierProvider(create: (context) => GreenManageProvider()), ChangeNotifierProvider(create: (context) => InspectionManageProvider()), - ChangeNotifierProvider(create: (context)=>AnouncementProvider()), + ChangeNotifierProvider(create: (context) => AnouncementProvider()), ], child: GetMaterialApp( title: '小蜜蜂管家', diff --git a/pubspec.lock b/pubspec.lock index 7741b48..9351d81 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -310,6 +310,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" + jpush_flutter: + dependency: "direct main" + description: + name: jpush_flutter + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.3" logger: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index fecc8e3..c7c26e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,6 +59,7 @@ dependencies: hive: ^1.4.4+1 hive_flutter: ^0.3.1 + jpush_flutter: ^0.6.3 dev_dependencies: flutter_test: