channel_util.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import 'package:atmob_channel_reader/atmob_channel_reader.dart';
  2. import '../../device/atmob_platform_info.dart';
  3. import '../../utils/mmkv_util.dart';
  4. import '../data/consts/constants.dart';
  5. class ChannelUtil {
  6. ChannelUtil._();
  7. static Future<void> initChannel() async {
  8. await AtmobChannelReader.default4Test(Constants.appDefaultChannel,
  9. Constants.appDefaultAppId, Constants.appDefaultTgPlatformId);
  10. String? channel = KVUtil.getString(
  11. Constants.appChanelName, await AtmobChannelReader.getChannel());
  12. KVUtil.putString(Constants.appChanelName, channel);
  13. int? channelId = KVUtil.getInt(Constants.appChannelId, -1);
  14. if (channelId == -1) {
  15. channelId = await AtmobChannelReader.getAppId();
  16. }
  17. if (channelId != null) {
  18. KVUtil.putInt(Constants.appChannelId, channelId);
  19. }
  20. int? appTgPlatformId = KVUtil.getInt(Constants.appTgPlatformId, -1);
  21. if (appTgPlatformId == -1) {
  22. appTgPlatformId = await AtmobChannelReader.getTgPlatformId();
  23. }
  24. if (appTgPlatformId != null) {
  25. KVUtil.putInt(Constants.appTgPlatformId, appTgPlatformId);
  26. }
  27. atmobPlatformInfo.setChannelName(channel);
  28. atmobPlatformInfo.setAppId(channelId);
  29. atmobPlatformInfo.setTgPlatform(appTgPlatformId);
  30. }
  31. }