From 1a61d080f7b7b55de3a53e707c18e6c0a7291217 Mon Sep 17 00:00:00 2001 From: Liuyf Date: Tue, 25 Feb 2025 15:52:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E5=8E=82=E5=95=86?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0token=E4=B8=80=E5=AE=9A=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=86=85=E4=B8=8D=E4=BC=9A=E9=87=8D=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tools/push/xs_jPhush.dart | 39 +++++++++++++++++++++-------------- lib/tools/storage.dart | 5 +++-- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/tools/push/xs_jPhush.dart b/lib/tools/push/xs_jPhush.dart index bb39b106..701fee30 100755 --- a/lib/tools/push/xs_jPhush.dart +++ b/lib/tools/push/xs_jPhush.dart @@ -28,8 +28,8 @@ class XSJPushProvider { 9: 'jiguang' }; final JPush jpush = JPush(); - late Completer> _jpushRegistrationIdCompleter; - late Completer> _vendorTokenCompleter; + Completer>? _jpushRegistrationIdCompleter; + Completer>? _vendorTokenCompleter; Future resetJPushService() async { debugPrint("resetJPushService start"); @@ -86,39 +86,42 @@ class XSJPushProvider { case CMD_GET_REGISTRATION_ID: final bool isNullOrBlank = GetUtils.isNullOrBlank(data['message']) ?? true; - if (!_jpushRegistrationIdCompleter.isCompleted && !isNullOrBlank) { + if (!(_jpushRegistrationIdCompleter?.isCompleted ?? true) && + !isNullOrBlank) { await Storage.setString(pushDeviceID, data['message']); AppLog.log('flutter get registration id : ${data['message']}'); - _jpushRegistrationIdCompleter.complete({ + _jpushRegistrationIdCompleter?.complete({ 'channel': 'jiguang', 'channelToken': data['message'] }); + final String? channel2TokenStr = + await Storage.getString(vendorPushChannelInfo); + if (Platform.isAndroid && + !(_vendorTokenCompleter?.isCompleted ?? true) && + channel2TokenStr != null) { + _vendorTokenCompleter?.complete(jsonDecode(channel2TokenStr)); + } } - - // final String? channel2TokenStr = - // await Storage.getString(vendorPushChannelInfo); - // if (Platform.isAndroid && channel2TokenStr != null) { - // _vendorTokenCompleter.complete(jsonDecode(channel2TokenStr)); - // } break; case CMD_GET_TOKEN: final bool isNullOrBlank = GetUtils.isNullOrBlank(data['token']) ?? true; - if (!_vendorTokenCompleter.isCompleted && !isNullOrBlank) { + if (!(_vendorTokenCompleter?.isCompleted ?? true) && + !isNullOrBlank) { final Map channel2Token = { 'channel': channelTypeMapping[data['platform']], 'channelToken': data['token'] }; await Storage.setString( vendorPushChannelInfo, jsonEncode(channel2Token)); - _vendorTokenCompleter.complete(channel2Token); + _vendorTokenCompleter?.complete(channel2Token); } break; } }, onReceiveNotification: (Map message) async { AppLog.log('onReceiveNotification: $message'); - debugPrint("addJPushEventHandler onReceiveNotification:$message"); + debugPrint('addJPushEventHandler onReceiveNotification:$message'); // showCustomNotification(message); }, onOpenNotification: (Map message) async { @@ -150,9 +153,15 @@ class XSJPushProvider { // jpush 统一推送通道设备绑定 Future bindPushChannels() async { try { + if (_jpushRegistrationIdCompleter == null || + _vendorTokenCompleter == null) { + return; + } debugPrint("await PushChannels start"); - var channels = await Future.wait( - [_jpushRegistrationIdCompleter.future, _vendorTokenCompleter.future]); + final List> channels = await Future.wait([ + _jpushRegistrationIdCompleter!.future, + _vendorTokenCompleter!.future + ]); final String? registrationId = await Storage.getString(pushDeviceID); debugPrint("await PushChannels end"); final MineUnbindPhoneOrEmailEntity entity = diff --git a/lib/tools/storage.dart b/lib/tools/storage.dart index eb251a53..5132a39c 100755 --- a/lib/tools/storage.dart +++ b/lib/tools/storage.dart @@ -152,10 +152,11 @@ class Storage { // 移除所有的键值对 static Future clearAll() async { final SharedPreferences sp = await SharedPreferences.getInstance(); - sp.clear(); + // sp.clear(); + sp.remove(saveUserLoginData); // 重新设置需要保留的数据 //退出登录不清除隐私协议同意状态 - await setString(isAgreePrivacy, isAgreePrivacy); + // await setString(isAgreePrivacy, isAgreePrivacy); } static Future getUid() async {