| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import 'package:flutter/services.dart';
- import 'package:jpush_flutter/jpush_flutter.dart';
- import 'package:jpush_flutter/jpush_interface.dart';
- import 'package:location/data/consts/build_config.dart';
- import 'package:location/utils/atmob_log.dart';
- class JpushHelper {
- static const String tag = 'JpushHelper';
- JpushHelper._();
- static JPushFlutterInterface? jpush;
- static void init() async {
- jpush = JPush.newJPush();
- _setJPushEventHandler();
- jpush!.setAuth(enable: true);
- jpush!.setup(
- appKey: "cd602bd396037438bb9ead5a",
- debug: BuildConfig.isDebug,
- );
- final id = await JpushHelper.getRegistrationId();
- AtmobLog.d(tag, 'RegistrationId:$id');
- }
- static Future<String> getRegistrationId() {
- if (jpush == null) {
- throw Exception('JPush not initialized');
- }
- return jpush!.getRegistrationID();
- }
- static void _setJPushEventHandler() {
- try {
- if (jpush == null) {
- throw Exception('JPush not initialized');
- }
- 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");
- }, onReceiveNotificationAuthorization:
- (Map<String, dynamic> message) async {
- print("flutter onReceiveNotificationAuthorization: $message");
- }, onNotifyMessageUnShow: (Map<String, dynamic> message) async {
- print("flutter onNotifyMessageUnShow: $message");
- }, onInAppMessageShow: (Map<String, dynamic> message) async {
- print("flutter onInAppMessageShow: $message");
- }, onCommandResult: (Map<String, dynamic> message) async {
- print("flutter onCommandResult: $message");
- }, onInAppMessageClick: (Map<String, dynamic> message) async {
- print("flutter onInAppMessageClick: $message");
- }, onConnected: (Map<String, dynamic> message) async {
- print("flutter onConnected: $message");
- }, onReceiveDeviceToken: (Map<String, dynamic> message) async {
- print("flutter onReceiveDeviceToken: $message");
- });
- } on PlatformException {
- AtmobLog.e(tag,
- 'JPush event handler error: JPush not initialized or platform error');
- } catch (e) {
- AtmobLog.e(tag, 'JPush event handler error: $e');
- }
- }
- }
|