diff --git a/ios/Classes/Api/MOP_registerSyncExtensionApi.m b/ios/Classes/Api/MOP_registerSyncExtensionApi.m index c928d25..57dd751 100644 --- a/ios/Classes/Api/MOP_registerSyncExtensionApi.m +++ b/ios/Classes/Api/MOP_registerSyncExtensionApi.m @@ -8,6 +8,7 @@ #import "MOP_registerSyncExtensionApi.h" #import "MopPlugin.h" #import +#import "PhizLanguageData.h" @implementation MOP_registerSyncExtensionApi @@ -17,10 +18,17 @@ FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; [[FATClient sharedClient] registerSyncExtensionApi:self.name handler:^NSDictionary *(FATAppletInfo *appletInfo, id param) { if([self.name isEqualToString:@"getLanguageCodeSync"]){ - NSString *languageCode = [[NSLocale preferredLanguages] firstObject]; - NSString *shortCode = [[NSLocale componentsFromLocaleIdentifier:languageCode] objectForKey:NSLocaleLanguageCode]; - NSString *countryCode = [NSString stringWithFormat:@"%@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]]; - NSDictionary *resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode}; + NSDictionary *resultDict = [NSDictionary dictionary]; + if([PhizLanguageData sharedInstance].languageCode == nil){ + NSString *languageCode = [[NSLocale preferredLanguages] firstObject]; + NSString *shortCode = [[NSLocale componentsFromLocaleIdentifier:languageCode] objectForKey:NSLocaleLanguageCode]; + NSString *countryCode = [NSString stringWithFormat:@"%@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]]; + resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode}; + }else{ + NSString* shortCode = [PhizLanguageData sharedInstance].languageCode; + NSString* countryCode = [PhizLanguageData sharedInstance].countryCode; + resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode}; + } return resultDict; } return @{}; @@ -28,4 +36,5 @@ success(@{}); } + @end diff --git a/ios/Classes/Api/PhizLanguageData.h b/ios/Classes/Api/PhizLanguageData.h new file mode 100644 index 0000000..6093159 --- /dev/null +++ b/ios/Classes/Api/PhizLanguageData.h @@ -0,0 +1,20 @@ +// +// PhizLanguageData.h +// FinDemo +// +// Created by stewen on 2023/8/4. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface PhizLanguageData : NSObject + +@property (nonatomic, copy) NSString *languageCode; +@property (nonatomic, copy) NSString *countryCode; + ++ (instancetype)sharedInstance; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/PhizLanguageData.m b/ios/Classes/Api/PhizLanguageData.m new file mode 100644 index 0000000..bad11e6 --- /dev/null +++ b/ios/Classes/Api/PhizLanguageData.m @@ -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 \ No newline at end of file diff --git a/ios/Classes/MopPlugin.h b/ios/Classes/MopPlugin.h index 62cb5f0..76c822c 100644 --- a/ios/Classes/MopPlugin.h +++ b/ios/Classes/MopPlugin.h @@ -10,6 +10,7 @@ @property FlutterMethodChannel *shareMethodChannel; @property FlutterMethodChannel *shareAppletMethodChannel; @property FlutterMethodChannel *appletMethodChannel; +@property FlutterMethodChannel *phizMethodChannel; + (instancetype) instance; @end diff --git a/ios/Classes/MopPlugin.m b/ios/Classes/MopPlugin.m index 18ba4a9..3578d98 100644 --- a/ios/Classes/MopPlugin.m +++ b/ios/Classes/MopPlugin.m @@ -6,6 +6,7 @@ #import #import "MopShareView.h" #import +#import "PhizLanguageData.h" @implementation MopEventStream { FlutterEventSink _eventSink; @@ -64,7 +65,12 @@ static MopPlugin *_instance; binaryMessenger:[registrar messenger]]; [registrar addMethodCallDelegate:_instance channel:appletShareChannel]; _instance.shareAppletMethodChannel = appletShareChannel; - + //phiz + FlutterMethodChannel* phizChannel = [FlutterMethodChannel + methodChannelWithName:@"Phiz" + binaryMessenger:[registrar messenger]]; + [registrar addMethodCallDelegate:_instance channel:phizChannel]; + _instance.phizMethodChannel = phizChannel; } + (instancetype)instance{ @@ -136,6 +142,13 @@ static MopPlugin *_instance; // [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 { MOPApiRequest* request = [[MOPApiRequest alloc] init]; request.command = call.method;