From 405b63b885eec29056f2e729619ba5c15284dd95 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 17:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E6=88=90jpush?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 6 ++++++ lib/main.dart | 22 ++++++++++++++++++++++ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 4 files changed, 36 insertions(+) diff --git a/android/app/build.gradle b/android/app/build.gradle index ffc1b934..0e3cc76f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -49,6 +49,12 @@ android { targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + manifestPlaceholders = [ + JPUSH_PKGNAME : applicationId, + JPUSH_APPKEY : "6a2c6507e3e8b3187ac1c9f9", + JPUSH_CHANNEL : "developer-default", + ] + } signingConfigs { diff --git a/lib/main.dart b/lib/main.dart index ee0fb1fc..a14bb29f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_picker/flutter_picker.dart'; import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; +import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; @@ -21,6 +22,27 @@ import 'package:akuCommunity/utils/developer_util.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); + 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: "6a2c6507e3e8b3187ac1c9f9", + channel: "developer-default", + production: false, + debug: true, // 设置是否打印 debug 日志 + ); DeveloperUtil.setDev(true); runApp(MyApp()); } diff --git a/pubspec.lock b/pubspec.lock index 362f28a6..96f00fd6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -609,6 +609,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.3.4" + jpush_flutter: + dependency: "direct main" + description: + name: jpush_flutter + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.3" js: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f89c5dd0..d54b6ffe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -95,6 +95,7 @@ dependencies: git: url: http://192.168.2.201:8099/aku_fe/power_logger.git flutter_rating_bar: ^3.2.0+1 + jpush_flutter: ^0.6.3 dev_dependencies: flutter_test: