method_chanel_ios_util.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'dart:io';
  2. import 'package:flutter/services.dart';
  3. import 'package:get/get.dart';
  4. import 'package:keyboard/module/character_custom/character_custom_page.dart';
  5. import 'package:keyboard/module/login/login_page.dart';
  6. import 'package:keyboard/module/main/main_page.dart';
  7. import 'package:keyboard/module/store/store_page.dart';
  8. import '../module/intimacy_scale/intimacy_scale_page.dart';
  9. class MethodChanelIOSUtil {
  10. static final MethodChanelIOSUtil _instance = MethodChanelIOSUtil._internal();
  11. factory MethodChanelIOSUtil() => _instance;
  12. MethodChanelIOSUtil._internal();
  13. static const MethodChannel _channel = MethodChannel('keyboard_ios');
  14. static void initialize() {
  15. _channel.setMethodCallHandler(_handleMethod);
  16. }
  17. static Future<dynamic> _handleMethod(MethodCall call) async {
  18. switch (call.method) {
  19. case 'navigateToLogin':
  20. LoginPage.start();
  21. break;
  22. case 'navigateToMember':
  23. StorePage.start();
  24. break;
  25. case 'navigateToCharacterMarket':
  26. MainPage.start(arguments: {"tabName": "character"});
  27. break;
  28. case 'navigateToCustomCharacter':
  29. CharacterCustomPage.start();
  30. break;
  31. case 'navigateToIntimacy':
  32. IntimacyScalePage.start();
  33. break;
  34. default:
  35. throw PlatformException(
  36. code: 'Unimplemented',
  37. details: '未实现的方法: ${call.method}',
  38. );
  39. }
  40. }
  41. // 保存token到ios端
  42. static Future<void> saveAuthToken(String token) async {
  43. // 通知iOS键盘扩展
  44. if (Platform.isIOS) {
  45. _channel.invokeMethod('saveAuthToken', {'token': token});
  46. }
  47. }
  48. // 保存idfv到ios端
  49. static Future<void> saveIDFV(String? idfv) async {
  50. // 通知iOS键盘扩展
  51. if (Platform.isIOS) {
  52. _channel.invokeMethod('saveIDFV', {'idfv': idfv});
  53. }
  54. }
  55. // 保存idfa到ios端
  56. static Future<void> saveIDFA(String? idfa) async {
  57. // 通知iOS键盘扩展
  58. if (Platform.isIOS) {
  59. _channel.invokeMethod('saveIDFA', {'idfa': idfa});
  60. }
  61. }
  62. // 保存token到ios端
  63. static Future<void> clearAuthToken() async {
  64. // 通知iOS键盘扩展
  65. if (Platform.isIOS) {
  66. _channel.invokeMethod('clearAuthToken');
  67. }
  68. }
  69. }