fix: 处理厂商平台token一定时间内不会重复获取问题
This commit is contained in:
parent
5aa6958acc
commit
1a61d080f7
@ -28,8 +28,8 @@ class XSJPushProvider {
|
||||
9: 'jiguang'
|
||||
};
|
||||
final JPush jpush = JPush();
|
||||
late Completer<Map<String, dynamic>> _jpushRegistrationIdCompleter;
|
||||
late Completer<Map<String, dynamic>> _vendorTokenCompleter;
|
||||
Completer<Map<String, dynamic>>? _jpushRegistrationIdCompleter;
|
||||
Completer<Map<String, dynamic>>? _vendorTokenCompleter;
|
||||
|
||||
Future<void> 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(<String, dynamic>{
|
||||
_jpushRegistrationIdCompleter?.complete(<String, dynamic>{
|
||||
'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<String, dynamic> channel2Token = <String, dynamic>{
|
||||
'channel': channelTypeMapping[data['platform']],
|
||||
'channelToken': data['token']
|
||||
};
|
||||
await Storage.setString(
|
||||
vendorPushChannelInfo, jsonEncode(channel2Token));
|
||||
_vendorTokenCompleter.complete(channel2Token);
|
||||
_vendorTokenCompleter?.complete(channel2Token);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
onReceiveNotification: (Map<String, dynamic> message) async {
|
||||
AppLog.log('onReceiveNotification: $message');
|
||||
debugPrint("addJPushEventHandler onReceiveNotification:$message");
|
||||
debugPrint('addJPushEventHandler onReceiveNotification:$message');
|
||||
// showCustomNotification(message);
|
||||
},
|
||||
onOpenNotification: (Map<String, dynamic> message) async {
|
||||
@ -150,9 +153,15 @@ class XSJPushProvider {
|
||||
// jpush 统一推送通道设备绑定
|
||||
Future<void> bindPushChannels() async {
|
||||
try {
|
||||
if (_jpushRegistrationIdCompleter == null ||
|
||||
_vendorTokenCompleter == null) {
|
||||
return;
|
||||
}
|
||||
debugPrint("await PushChannels start");
|
||||
var channels = await Future.wait(
|
||||
[_jpushRegistrationIdCompleter.future, _vendorTokenCompleter.future]);
|
||||
final List<Map<String, dynamic>> channels = await Future.wait([
|
||||
_jpushRegistrationIdCompleter!.future,
|
||||
_vendorTokenCompleter!.future
|
||||
]);
|
||||
final String? registrationId = await Storage.getString(pushDeviceID);
|
||||
debugPrint("await PushChannels end");
|
||||
final MineUnbindPhoneOrEmailEntity entity =
|
||||
|
||||
@ -152,10 +152,11 @@ class Storage {
|
||||
// 移除所有的键值对
|
||||
static Future<void> 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<String?> getUid() async {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user