ios同步方法更改

phiz
stewen 2023-08-04 17:25:36 +08:00
parent 9951bebc56
commit 58a8e5b804
5 changed files with 71 additions and 5 deletions

View File

@ -8,6 +8,7 @@
#import "MOP_registerSyncExtensionApi.h" #import "MOP_registerSyncExtensionApi.h"
#import "MopPlugin.h" #import "MopPlugin.h"
#import <FinApplet/FinApplet.h> #import <FinApplet/FinApplet.h>
#import "PhizLanguageData.h"
@implementation MOP_registerSyncExtensionApi @implementation MOP_registerSyncExtensionApi
@ -17,10 +18,17 @@
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
[[FATClient sharedClient] registerSyncExtensionApi:self.name handler:^NSDictionary *(FATAppletInfo *appletInfo, id param) { [[FATClient sharedClient] registerSyncExtensionApi:self.name handler:^NSDictionary *(FATAppletInfo *appletInfo, id param) {
if([self.name isEqualToString:@"getLanguageCodeSync"]){ if([self.name isEqualToString:@"getLanguageCodeSync"]){
NSDictionary *resultDict = [NSDictionary dictionary];
if([PhizLanguageData sharedInstance].languageCode == nil){
NSString *languageCode = [[NSLocale preferredLanguages] firstObject]; NSString *languageCode = [[NSLocale preferredLanguages] firstObject];
NSString *shortCode = [[NSLocale componentsFromLocaleIdentifier:languageCode] objectForKey:NSLocaleLanguageCode]; NSString *shortCode = [[NSLocale componentsFromLocaleIdentifier:languageCode] objectForKey:NSLocaleLanguageCode];
NSString *countryCode = [NSString stringWithFormat:@"%@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]]; NSString *countryCode = [NSString stringWithFormat:@"%@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]];
NSDictionary *resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode}; resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode};
}else{
NSString* shortCode = [PhizLanguageData sharedInstance].languageCode;
NSString* countryCode = [PhizLanguageData sharedInstance].countryCode;
resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode};
}
return resultDict; return resultDict;
} }
return @{}; return @{};
@ -28,4 +36,5 @@
success(@{}); success(@{});
} }
@end @end

View File

@ -0,0 +1,20 @@
//
// PhizLanguageData.h
// FinDemo
//
// Created by stewen on 2023/8/4.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PhizLanguageData : NSObject
@property (nonatomic, copy) NSString *languageCode;
@property (nonatomic, copy) NSString *countryCode;
+ (instancetype)sharedInstance;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,23 @@
//
// PhizLanguageData.m
// FinDemo
//
// Created by stewen on 2023/8/4.
//
#import "PhizLanguageData.h"
@implementation PhizLanguageData
+ (instancetype)sharedInstance {
static PhizLanguageData *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
//sharedInstance.languageCode = @"en"; // Set default language code
//sharedInstance.countryCode = @"US";
});
return sharedInstance;
}
@end

View File

@ -10,6 +10,7 @@
@property FlutterMethodChannel *shareMethodChannel; @property FlutterMethodChannel *shareMethodChannel;
@property FlutterMethodChannel *shareAppletMethodChannel; @property FlutterMethodChannel *shareAppletMethodChannel;
@property FlutterMethodChannel *appletMethodChannel; @property FlutterMethodChannel *appletMethodChannel;
@property FlutterMethodChannel *phizMethodChannel;
+ (instancetype) instance; + (instancetype) instance;
@end @end

View File

@ -6,6 +6,7 @@
#import <mop/MOPTools.h> #import <mop/MOPTools.h>
#import "MopShareView.h" #import "MopShareView.h"
#import <UIView+MOPFATToast.h> #import <UIView+MOPFATToast.h>
#import "PhizLanguageData.h"
@implementation MopEventStream { @implementation MopEventStream {
FlutterEventSink _eventSink; FlutterEventSink _eventSink;
@ -64,7 +65,12 @@ static MopPlugin *_instance;
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
[registrar addMethodCallDelegate:_instance channel:appletShareChannel]; [registrar addMethodCallDelegate:_instance channel:appletShareChannel];
_instance.shareAppletMethodChannel = appletShareChannel; _instance.shareAppletMethodChannel = appletShareChannel;
//phiz
FlutterMethodChannel* phizChannel = [FlutterMethodChannel
methodChannelWithName:@"Phiz"
binaryMessenger:[registrar messenger]];
[registrar addMethodCallDelegate:_instance channel:phizChannel];
_instance.phizMethodChannel = phizChannel;
} }
+ (instancetype)instance{ + (instancetype)instance{
@ -136,6 +142,13 @@ static MopPlugin *_instance;
// [MOPAppletDelegate instance].bindGetPhoneNumbers(jsonDic); // [MOPAppletDelegate instance].bindGetPhoneNumbers(jsonDic);
} }
} }
else if ([@"updateLanguage" isEqualToString:call.method]) {
NSLog(@"updateLanguage");
NSString cCode = call.arguments[@"countryCode"]];
NSString cLang = call.arguments[@"languageCode"]];
[PhizLanguageData sharedInstance].countryCode = cCode;
[PhizLanguageData sharedInstance].languageCode = cLang;
}
else { else {
MOPApiRequest* request = [[MOPApiRequest alloc] init]; MOPApiRequest* request = [[MOPApiRequest alloc] init];
request.command = call.method; request.command = call.method;