| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import 'dart:io';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:keyboard/module/character_custom/character_custom_page.dart';
- import 'package:keyboard/module/login/login_page.dart';
- import 'package:keyboard/module/main/main_page.dart';
- import 'package:keyboard/module/store/store_page.dart';
- import 'package:keyboard/utils/default_keyboard_helper.dart';
- import 'package:keyboard/utils/toast_util.dart';
- import '../module/intimacy_scale/intimacy_scale_page.dart';
- import '../widget/platform_util.dart';
- class MethodChanelIOSUtil {
- static final MethodChanelIOSUtil _instance = MethodChanelIOSUtil._internal();
- factory MethodChanelIOSUtil() => _instance;
- MethodChanelIOSUtil._internal();
- static const MethodChannel _channel = MethodChannel('keyboard_ios');
- static void initialize() {
- _channel.setMethodCallHandler(_handleMethod);
- // 默认键盘切换监听器
- DefaultKeyboardHelper.init();
- }
- static Future<dynamic> _handleMethod(MethodCall call) async {
- switch (call.method) {
- case 'navigateToLogin':
- ToastUtil.show("navigateToLogin");
- LoginPage.start();
- break;
- case 'navigateToMember':
- StorePage.start();
- break;
- case 'navigateToCharacterMarket':
- MainPage.start(arguments: {"tabName": "character"});
- break;
- case 'navigateToCustomCharacter':
- CharacterCustomPage.start();
- break;
- case 'navigateToIntimacy':
- IntimacyScalePage.start();
- break;
- case 'isKeyboardAdd':
- break;
- default:
- throw PlatformException(
- code: 'Unimplemented',
- details: '未实现的方法: ${call.method}',
- );
- }
- }
- // 保存token到ios端
- static Future<void> saveAuthToken(String token) async {
- // 通知iOS键盘扩展
- if (PlatformUtil.isIOS) {
- _channel.invokeMethod('saveAuthToken', {'token': token});
- }
- }
- // 保存idfv到ios端
- static Future<void> saveIDFV(String? idfv) async {
- // 通知iOS键盘扩展
- if (PlatformUtil.isIOS) {
- _channel.invokeMethod('saveIDFV', {'idfv': idfv});
- }
- }
- // 保存idfa到ios端
- static Future<void> saveIDFA(String? idfa) async {
- // 通知iOS键盘扩展
- if (PlatformUtil.isIOS) {
- _channel.invokeMethod('saveIDFA', {'idfa': idfa});
- }
- }
- // 保存token到ios端
- static Future<void> clearAuthToken() async {
- // 通知iOS键盘扩展
- if (PlatformUtil.isIOS) {
- _channel.invokeMethod('clearAuthToken');
- }
- }
- // 检查键盘是否已添加
- static Future<bool> isDefaultKeyboard() async {
- try {
- // 调用原生方法并等待返回结果
- final bool result = await _channel.invokeMethod('isDefaultKeyboard');
- return result;
- } on PlatformException catch (e) {
- print('检查键盘是否为默认键盘: ${e.message}');
- return false; // 发生错误时返回 false
- }
- }
- // 检查键盘是否已添加
- static Future<bool> isKeyboardAdded() async {
- try {
- // 调用原生方法并等待返回结果
- final bool result = await _channel.invokeMethod('isKeyboardAdded');
- return result;
- } on PlatformException catch (e) {
- print('检查键盘是否添加失败: ${e.message}');
- return false; // 发生错误时返回 false
- }
- }
- static Future<void> openKeyboardGuide() async {
- // 通知iOS键盘扩展
- if (PlatformUtil.isIOS) {
- _channel.invokeMethod('openKeyboardGuide');
- }
- }
- // 检查是否有优惠
- static Future<bool> isHasDiscount(String appleGoodId) async {
- try {
- // 调用原生方法并等待返回结果
- final bool result = await _channel.invokeMethod('isHasDiscount', {'appleGoodId': appleGoodId});
- return result;
- } on PlatformException catch (e) {
- print('检查商品是否有优惠: ${e.message}');
- return false; // 发生错误时返回 false
- }
- }
- }
|