浏览代码

[new]增加极光推送id上报

zk 4 月之前
父节点
当前提交
84badcac0b

+ 6 - 0
android/app/build.gradle

@@ -37,6 +37,12 @@ android {
             //noinspection ChromeOsAbiSupport
             abiFilters "arm64-v8a"
         }
+
+        manifestPlaceholders = [
+                JPUSH_PKGNAME: rootProject.ext.applicationId,
+                JPUSH_APPKEY : "cd602bd396037438bb9ead5a", // NOTE: JPush 上注册的包名对应的 Appkey.
+                JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
+        ]
     }
 
     signingConfigs {

+ 9 - 4
lib/data/repositories/account_repository.dart

@@ -1,4 +1,5 @@
 import 'dart:async';
+import 'dart:io';
 
 import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
@@ -19,6 +20,7 @@ import 'package:location/di/get_it.dart';
 import 'package:location/module/main/today_track_helper.dart';
 import 'package:location/push_notification/ios_push_notification_service.dart';
 import 'package:location/resource/string.gen.dart';
+import 'package:location/sdk/jpush/jpush_helper.dart';
 import 'package:location/socket/atmob_location_client.dart';
 import 'package:location/utils/async_util.dart';
 import 'package:location/utils/atmob_log.dart';
@@ -253,11 +255,14 @@ class AccountRepository {
   ///请求推送的数据
   Future<void> onRequestNotificationReport() async {
     // 初始化推送服务
-    var tokenStr = await IosPushNotificationService.getDeviceToken();
-    print("tokenStrsfsdf---${tokenStr}");
+    String? token;
+    if (Platform.isIOS) {
+      token = await IosPushNotificationService.getDeviceToken();
+    } else if (Platform.isAndroid) {
+      token = await JpushHelper.getRegistrationId();
+    }
     return atmobApi
-        .notificationReport(
-            NotificationReportRequest(deviceToken: tokenStr as String))
+        .notificationReport(NotificationReportRequest(deviceToken: token ?? ''))
         .then(HttpHandler.handle(false))
         .then((response) {})
         .catchError((_) {});

+ 3 - 0
lib/main.dart

@@ -14,6 +14,7 @@ import 'package:location/resource/string_source.dart';
 import 'package:location/router/app_pages.dart';
 import 'package:location/sdk/bugly/bugly_helper.dart';
 import 'package:location/sdk/gravity/gravity_helper.dart';
+import 'package:location/sdk/jpush/jpush_helper.dart';
 import 'package:location/sdk/map/map_helper.dart';
 import 'package:location/sdk/quicklogin/quick_login_helper.dart';
 import 'package:location/sdk/umeng/umeng_helper.dart';
@@ -92,6 +93,8 @@ class AppInitTask implements EnsurePolicyGrant {
     UmengHelper.initCommon();
     //地图sdk
     await MapHelper.init();
+    //极光推送
+    JpushHelper.init();
     //一键登录
     QuickLoginHelper.init();
   }

+ 0 - 1
lib/resource/string.gen.dart

@@ -2,7 +2,6 @@ import 'package:get/get.dart';
 
 class StringName {
   StringName._();
-
   static String get appName => 'app_name'.tr; // 寻迹速查定位
   static String get mainTabHome => 'main_tab_home'.tr; // 首页
   static String get mainTabCamera => 'main_tab_camera'.tr; // 扫一扫

+ 19 - 0
lib/sdk/jpush/jpush_helper.dart

@@ -0,0 +1,19 @@
+import 'package:jpush_flutter/jpush_flutter.dart';
+import 'package:jpush_flutter/jpush_interface.dart';
+
+class JpushHelper {
+  JpushHelper._();
+
+  static JPushFlutterInterface? jpush;
+
+  static void init() {
+    jpush = JPush.newJPush();
+  }
+
+  static Future<String> getRegistrationId() {
+    if (jpush == null) {
+      throw Exception('JPush not initialized');
+    }
+    return jpush!.getRegistrationID();
+  }
+}

+ 3 - 0
pubspec.yaml

@@ -158,6 +158,9 @@ dependencies:
   #获取wifi相关信息
   network_info_plus: ^6.1.4
 
+  #极光推送
+  jpush_flutter: ^3.3.1
+
   #一键登录
   quickpass_yidun_flutter: ^1.5.6