mop-flutter-sdk/ios/Classes/Api/MOP_initialize.m

141 lines
6.4 KiB
Dart
Raw Normal View History

2020-02-27 17:21:45 +08:00
//
// MOP_initialize.m
// mop
//
// Created by 杨涛 on 2020/2/27.
//
#import "MOP_initialize.h"
#import <FinApplet/FinApplet.h>
2023-08-02 19:59:34 +08:00
//#import <FinAppletExt/FinAppletExt.h>
#import "FinAppletExt.h"
2023-08-02 17:31:33 +08:00
#import <FinAppletClipBoard/FinAppletClipBoard.h>
2023-09-26 14:15:08 +08:00
#import <FinAppletBLE/FinAppletBLE.h>
2021-12-22 17:32:18 +08:00
#import "MOPTools.h"
2020-02-27 17:21:45 +08:00
@implementation MOP_initialize
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
if (!self.appkey || !self.secret) {
2021-12-22 17:32:18 +08:00
failure(@"sdkkey 或 secret不能为空");
2020-02-27 17:21:45 +08:00
return;
}
if (!self.apiServer || [self.apiServer isEqualToString:@""]) {
2021-01-12 15:24:37 +08:00
self.apiServer = @"https://api.finclip.com";
2020-02-27 17:21:45 +08:00
}
if (!self.apiPrefix|| [self.apiPrefix isEqualToString:@""]) {
self.apiPrefix = @"/api/v1/mop";
}
2021-12-22 17:32:18 +08:00
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"];
2021-12-28 20:26:23 +08:00
storeConfig.sdkSecret = dict[@"sdkSecret"];
2021-12-22 17:32:18 +08:00
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 {
2021-12-28 20:26:23 +08:00
config = [FATConfig configWithAppSecret:self.secret appKey:self.appkey];
2021-12-22 17:32:18 +08:00
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;
2020-05-19 16:42:10 +08:00
}
2021-12-22 17:32:18 +08:00
2020-07-27 09:13:55 +08:00
NSLog(@"disablePermission:%d",self.disablePermission);
config.disableAuthorize = self.disablePermission;
2021-12-22 17:32:18 +08:00
config.currentUserId = [self.userId copy];
config.appletIntervalUpdateLimit = self.appletIntervalUpdateLimit;
// bool debug = false,
// bool bindAppletWithMainProcess = false,
// List<FinStoreConfig>? finStoreConfigs,
// UIConfig? uiConfig,
// String? customWebViewUserAgent,
// int appletIntervalUpdateLimit = 0,
// int maxRunningApplet = 5,
2020-02-27 17:21:45 +08:00
NSError* error = nil;
2020-07-31 15:33:48 +08:00
FATUIConfig *uiconfig = [[FATUIConfig alloc]init];
2021-12-22 17:32:18 +08:00
if (_uiConfig) {
if (_uiConfig[@"navigationTitleTextAttributes"]) {
uiconfig.navigationTitleTextAttributes = _uiConfig[@"navigationTitleTextAttributes"];
}
2023-03-21 17:46:50 +08:00
if (_uiConfig[@"webViewProgressBarColor"]) {
uiconfig.progressBarColor = [MOPTools colorWithRGBHex:[_uiConfig[@"webViewProgressBarColor"] intValue]];
2021-12-22 17:32:18 +08:00
}
uiconfig.hideFeedbackMenu = [_uiConfig[@"isHideFeedbackAndComplaints"] boolValue];
uiconfig.hideForwardMenu = [_uiConfig[@"isHideForwardMenu"] boolValue];
uiconfig.autoAdaptDarkMode = [_uiConfig[@"autoAdaptDarkMode"] boolValue];
uiconfig.hideShareAppletMenu = [_uiConfig[@"isHideShareAppletMenu"] boolValue];
2021-12-22 17:32:18 +08:00
uiconfig.appletText = _uiConfig[@"appletText"];
uiconfig.hideTransitionCloseButton = [_uiConfig[@"hideTransitionCloseButton"] boolValue];
uiconfig.disableSlideCloseAppletGesture = [_uiConfig[@"disableSlideCloseAppletGesture"] boolValue];
2021-12-22 17:32:18 +08:00
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;
2021-03-24 17:26:39 +08:00
// uiconfig.moreMenuStyle = FATMoreViewStyleNormal;
2020-07-31 15:33:48 +08:00
[[FATClient sharedClient] initWithConfig:config uiConfig:uiconfig error:&error];
2020-02-27 17:21:45 +08:00
if (error) {
failure(@"初始化失败");
return;
}
2021-11-18 18:18:14 +08:00
// [[FATExtClient sharedClient] fat_prepareExtensionApis];
2022-07-29 22:31:56 +08:00
[[FATClient sharedClient].logManager initLogWithLogDir:nil logLevel:FATLogLevelVerbose consoleLog:YES];
[[FATClient sharedClient] setEnableLog:YES];
2023-08-02 17:31:33 +08:00
// ClipBoard初始化
[FATClipBoardComponent registerComponent];
2020-02-27 17:21:45 +08:00
success(@{});
}
@end