channel_util.dart 1.3 KB

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