From 31b1c35a36f6c005eb5775c7b3c190b48e459d17 Mon Sep 17 00:00:00 2001 From: wangtao Date: Wed, 22 Dec 2021 17:32:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20iOS=E7=AB=AF=E6=96=B0=E5=A2=9EApi?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Classes/Api/MOP_finishRunningApplet.h | 2 +- ios/Classes/Api/MOP_initialize.h | 12 ++- ios/Classes/Api/MOP_initialize.m | 110 ++++++++++++++++++---- ios/Classes/Api/MOP_sendCustomEvent.h | 2 +- ios/Classes/Utils/MOPTools.h | 3 + ios/Classes/Utils/MOPTools.m | 85 +++++++++++++++++ ios/mop.podspec | 4 +- lib/mop.dart | 11 +++ 8 files changed, 205 insertions(+), 24 deletions(-) diff --git a/ios/Classes/Api/MOP_finishRunningApplet.h b/ios/Classes/Api/MOP_finishRunningApplet.h index da8c676..33a1cc2 100644 --- a/ios/Classes/Api/MOP_finishRunningApplet.h +++ b/ios/Classes/Api/MOP_finishRunningApplet.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MOP_finishRunningApplet : MOPBaseApi -@property (nonatomic, copy) NSString appletId; +@property (nonatomic, copy) NSString *appletId; @property (nonatomic, assign) BOOL animated; @end diff --git a/ios/Classes/Api/MOP_initialize.h b/ios/Classes/Api/MOP_initialize.h index 349c5a3..f3a7ded 100644 --- a/ios/Classes/Api/MOP_initialize.h +++ b/ios/Classes/Api/MOP_initialize.h @@ -11,15 +11,21 @@ NS_ASSUME_NONNULL_BEGIN @interface MOP_initialize : MOPBaseApi -@property (nonatomic, copy) NSString *appkey; +@property (nonatomic, copy) NSString *sdkkey; @property (nonatomic, copy) NSString *secret; @property (nonatomic, copy) NSString *apiServer; @property (nonatomic, copy) NSString *apiPrefix; @property (nonatomic, copy) NSString *cryptType; -@property (nonatomic, copy) NSString *userId; -@property (nonatomic, assign) BOOL disablePermission; @property (nonatomic, assign) BOOL encryptServerData; +@property (nonatomic, copy) NSString *userId; +@property (nonatomic, strong) NSArray *finStoreConfigs; +@property (nonatomic, strong) NSDictionary *uiConfig; +@property (nonatomic, copy) NSString *customWebViewUserAgent; +@property (nonatomic, assign) BOOL disablePermission; +@property (nonatomic, assign) NSInteger appletIntervalUpdateLimit; +@property (nonatomic, assign) NSInteger maxRunningApplet; + @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_initialize.m b/ios/Classes/Api/MOP_initialize.m index e774594..067a581 100644 --- a/ios/Classes/Api/MOP_initialize.m +++ b/ios/Classes/Api/MOP_initialize.m @@ -8,14 +8,15 @@ #import "MOP_initialize.h" #import #import +#import "MOPTools.h" // #import @implementation MOP_initialize - (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel { - if (!self.appkey || !self.secret) { - failure(@"appkey 或 secret不能为空"); + if (!self.sdkkey || !self.secret) { + failure(@"sdkkey 或 secret不能为空"); return; } if (!self.apiServer || [self.apiServer isEqualToString:@""]) { @@ -24,27 +25,102 @@ if (!self.apiPrefix|| [self.apiPrefix isEqualToString:@""]) { self.apiPrefix = @"/api/v1/mop"; } - FATConfig *config = [FATConfig configWithAppSecret:self.secret appKey:self.appkey]; - config.apiServer = [self.apiServer copy]; - config.apiPrefix = [self.apiPrefix copy]; - if([self.cryptType isEqualToString: @"SM"]) - { - config.cryptType = FATApiCryptTypeSM; + FATConfig *config; + if (_finStoreConfigs && _finStoreConfigs.count > 0) { + NSMutableArray *storeArrayM = [NSMutableArray array]; + for (NSDictionary *dict in _finStoreConfigs) { + FATStoreConfig *storeConfig = [[FATStoreConfig alloc] init]; + storeConfig.sdkKey = dict[@"sdkKey"]; + // storeConfig.sdkKey = @"22LyZEib0gLTQdU3MUauAb4V4W8Uxd/gMgmH8Hg1bGQ="; + storeConfig.sdkSecret = @"703b9026be3d6bc5"; + storeConfig.apiServer = dict[@"apiServer"]; + storeConfig.apmServer = dict[@"apmServer"]; + storeConfig.fingerprint = dict[@"fingerprint"]; + if ([@"SM" isEqualToString:dict[@"cryptType"]]) { + storeConfig.cryptType = FATApiCryptTypeSM; + } else { + storeConfig.cryptType = FATApiCryptTypeMD5; + } + storeConfig.encryptServerData = [dict[@"encryptServerData"] boolValue]; + [storeArrayM addObject:storeConfig]; + } + config = [FATConfig configWithStoreConfigs:storeArrayM]; + } else { + config = [FATConfig configWithAppSecret:self.secret appKey:self.sdkkey]; + config.apiServer = [self.apiServer copy]; + config.apiPrefix = [self.apiPrefix copy]; + if([self.cryptType isEqualToString: @"SM"]) + { + config.cryptType = FATApiCryptTypeSM; + } + else + { + config.cryptType = FATApiCryptTypeMD5; + } + + // encryptServerData + NSLog(@"encryptServerData:%d",self.encryptServerData); + config.encryptServerData = self.encryptServerData; } - else - { - config.cryptType = FATApiCryptTypeMD5; - } - config.currentUserId = [self.userId copy]; - // encryptServerData - NSLog(@"encryptServerData:%d",self.encryptServerData); - config.encryptServerData = self.encryptServerData; - + NSLog(@"disablePermission:%d",self.disablePermission); config.disableAuthorize = self.disablePermission; + config.currentUserId = [self.userId copy]; + config.appletIntervalUpdateLimit = self.appletIntervalUpdateLimit; + +// bool debug = false, +// bool bindAppletWithMainProcess = false, +// List? finStoreConfigs, +// UIConfig? uiConfig, +// String? customWebViewUserAgent, +// int appletIntervalUpdateLimit = 0, +// int maxRunningApplet = 5, + NSError* error = nil; FATUIConfig *uiconfig = [[FATUIConfig alloc]init]; uiconfig.autoAdaptDarkMode = YES; + if (_uiConfig) { + if (_uiConfig[@"navigationTitleTextAttributes"]) { + uiconfig.navigationTitleTextAttributes = _uiConfig[@"navigationTitleTextAttributes"]; + } + if (_uiConfig[@"progressBarColor"]) { + uiconfig.progressBarColor = [MOPTools colorWithRGBHex:[_uiConfig[@"progressBarColor"] intValue]]; + } + uiconfig.hideBackToHome = [_uiConfig[@"isHideBackHome"] boolValue]; + uiconfig.hideFeedbackMenu = [_uiConfig[@"isHideFeedbackAndComplaints"] boolValue]; + uiconfig.hideForwardMenu = [_uiConfig[@"isHideForwardMenu"] boolValue]; + uiconfig.autoAdaptDarkMode = [_uiConfig[@"autoAdaptDarkMode"] boolValue]; + + uiconfig.appletText = _uiConfig[@"appletText"]; + uiconfig.hideTransitionCloseButton = [_uiConfig[@"hideTransitionCloseButton"] boolValue]; + uiconfig.disableSlideCloseAppletGesture = _uiConfig[@"disableSlideCloseAppletGesture"]; + if (_uiConfig[@"capsuleConfig"]) { + NSDictionary *capsuleConfigDic = _uiConfig[@"capsuleConfig"]; + FATCapsuleConfig *capsuleConfig = [[FATCapsuleConfig alloc]init]; + capsuleConfig.capsuleWidth = [capsuleConfigDic[@"capsuleWidth"] floatValue]; + capsuleConfig.capsuleHeight = [capsuleConfigDic[@"capsuleHeight"] floatValue]; + capsuleConfig.capsuleRightMargin = [capsuleConfigDic[@"capsuleRightMargin"] floatValue]; + capsuleConfig.capsuleCornerRadius = [capsuleConfigDic[@"capsuleCornerRadius"] floatValue]; + capsuleConfig.capsuleBorderWidth = [capsuleConfigDic[@"capsuleBorderWidth"] floatValue]; + capsuleConfig.moreBtnWidth = [capsuleConfigDic[@"moreBtnWidth"] floatValue]; + capsuleConfig.moreBtnLeftMargin = [capsuleConfigDic[@"moreBtnLeftMargin"] floatValue]; + capsuleConfig.closeBtnWidth = [capsuleConfigDic[@"closeBtnWidth"] floatValue]; + capsuleConfig.closeBtnLeftMargin = [capsuleConfigDic[@"closeBtnLeftMargin"] floatValue]; + + + capsuleConfig.capsuleBorderLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBorderLightColor"] intValue]]; + capsuleConfig.capsuleBorderDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBorderDarkColor"] intValue]]; + capsuleConfig.capsuleBgLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBgLightColor"] intValue]]; + capsuleConfig.capsuleBgDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBgDarkColor"] intValue]]; + capsuleConfig.capsuleDividerLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleDividerLightColor"] intValue]]; + capsuleConfig.capsuleDividerDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleDividerDarkColor"] intValue]]; + uiconfig.capsuleConfig = capsuleConfig; + + } + + } + uiconfig.appendingCustomUserAgent = self.customWebViewUserAgent; + // uiconfig.moreMenuStyle = FATMoreViewStyleNormal; [[FATClient sharedClient] initWithConfig:config uiConfig:uiconfig error:&error]; if (error) { diff --git a/ios/Classes/Api/MOP_sendCustomEvent.h b/ios/Classes/Api/MOP_sendCustomEvent.h index 2218594..39436be 100644 --- a/ios/Classes/Api/MOP_sendCustomEvent.h +++ b/ios/Classes/Api/MOP_sendCustomEvent.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MOP_sendCustomEvent : MOPBaseApi -@property (nonatomic, strong) NSDictonary *eventData; +@property (nonatomic, strong) NSDictionary *eventData; @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Utils/MOPTools.h b/ios/Classes/Utils/MOPTools.h index b136dbe..af53889 100644 --- a/ios/Classes/Utils/MOPTools.h +++ b/ios/Classes/Utils/MOPTools.h @@ -13,6 +13,9 @@ NS_ASSUME_NONNULL_BEGIN + (UIViewController *)topViewController; + (UIViewController *)topViewController:(UIViewController *)rootViewController; ++ (UIColor *)colorWithRGBHex:(UInt32)hex; + ++ (UIColor *)fat_colorWithHexString:(NSString *)hexColor; @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Utils/MOPTools.m b/ios/Classes/Utils/MOPTools.m index e4cd688..236b2be 100644 --- a/ios/Classes/Utils/MOPTools.m +++ b/ios/Classes/Utils/MOPTools.m @@ -28,4 +28,89 @@ return [self topViewController:presentedViewController]; } ++ (UIColor *)colorWithRGBHex:(UInt32)hex +{ + int a = (hex >> 24) & 0xFF; + int r = (hex >> 16) & 0xFF; + int g = (hex >> 8) & 0xFF; + int b = (hex) & 0xFF; + + return [UIColor colorWithRed:r / 255.0f + green:g / 255.0f + blue:b / 255.0f + alpha:a / 255.0f]; +} + ++ (UIColor *)fat_colorWithHexString:(NSString *)hexColor { + if (!hexColor) return nil; + // 兼容black和white + if ([hexColor compare:@"black" options:NSCaseInsensitiveSearch] == NSOrderedSame) { + return UIColor.blackColor; + } else if ([hexColor compare:@"white" options:NSCaseInsensitiveSearch] == NSOrderedSame) { + return UIColor.whiteColor; + } + + NSString *cString = [[hexColor stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; + + if (cString.length == 0) return nil; + if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1]; + if ([cString containsString:@"0X"]) cString = [cString stringByReplacingOccurrencesOfString:@"0X" withString:@""]; + + if (cString.length == 3) { // 3位转成6位 + cString = [NSString stringWithFormat:@"%c%c%c%c%c%c", + [cString characterAtIndex:0], + [cString characterAtIndex:0], + [cString characterAtIndex:1], + [cString characterAtIndex:1], + [cString characterAtIndex:2], + [cString characterAtIndex:2]]; + } + if (cString.length == 4) { // 4位转为8位 + cString = [NSString stringWithFormat:@"%c%c%c%c%c%c%c%c", + [cString characterAtIndex:0], + [cString characterAtIndex:0], + [cString characterAtIndex:1], + [cString characterAtIndex:1], + [cString characterAtIndex:2], + [cString characterAtIndex:2], + [cString characterAtIndex:3], + [cString characterAtIndex:3]]; + } + + NSScanner *scanner = [NSScanner scannerWithString:cString]; + unsigned hexNum; + if (![scanner scanHexInt:&hexNum]) return [UIColor blackColor]; + + if (cString.length == 6) { + return [self fat_colorWithRGBHex:hexNum]; + } else if (cString.length == 8) { + return [self fat_colorWithARGBHex:hexNum]; + } + return nil; +} + ++ (UIColor *)fat_colorWithRGBHex:(UInt32)hex { + int red = (hex >> 16) & 0xFF; + int green = (hex >> 8) & 0xFF; + int blue = (hex)&0xFF; + return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:1.0f]; +} + ++ (UIColor *)fat_colorWithRGBAlphaHex:(UInt32)hex { + int red = (hex >> 24) & 0xFF; + int green = (hex >> 16) & 0xFF; + int blue = (hex >> 8) & 0xFF; + int alpha = hex & 0xFF; + return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:alpha / 255.0f]; +} + ++ (UIColor *)fat_colorWithARGBHex:(UInt32)hex { + int alpha = (hex >> 24) & 0xFF; + int red = (hex >> 16) & 0xFF; + int green = (hex >> 8) & 0xFF; + int blue = hex & 0xFF; + return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:alpha / 255.0f]; +} + + @end diff --git a/ios/mop.podspec b/ios/mop.podspec index 4c79944..637578a 100644 --- a/ios/mop.podspec +++ b/ios/mop.podspec @@ -17,7 +17,7 @@ A finclip miniprogram flutter sdk. s.dependency 'Flutter' s.ios.deployment_target = '9.0' - s.dependency 'FinApplet' , '2.34.12' - s.dependency 'FinAppletExt' , '2.34.12' + s.dependency 'FinApplet' , '2.34.11' + s.dependency 'FinAppletExt' , '2.34.11' end diff --git a/lib/mop.dart b/lib/mop.dart index dc59128..a4ab508 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -67,6 +67,14 @@ class UIConfig { FloatWindowConfig? floatWindowConfig; + //iOS中独有的设置属性 + //小程序里加载H5页面时进度条的颜色 格式 0xFFFFAA00 + int? progressBarColor; + //是否自适应暗黑模式。如果设置为true,则更多页面、关于等原生页面会随着手机切换暗黑,也自动调整为暗黑模式 + bool autoAdaptDarkMode = true; + //注入小程序统称appletText字符串,默认为“小程序”。 + String? appletText; + Map toMap() { return { "navigationTitleTextAttributes": navigationTitleTextAttributes, @@ -81,6 +89,9 @@ class UIConfig { "disableSlideCloseAppletGesture": disableSlideCloseAppletGesture, "capsuleConfig": capsuleConfig?.toMap(), "floatWindowConfig": floatWindowConfig?.toMap(), + "progressBarColor": progressBarColor, + "autoAdaptDarkMode": autoAdaptDarkMode, + "appletText": appletText }; } }