diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 438deb6..e0a2572 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/beetle/Desktop/finogeeks/gitlab/finosprite/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/beetle/Desktop/finogeeks/gitlab/finosprite/finclip-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2021-11-15 23:44:20.482386","version":"2.2.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/wangtao/Documents/fantai/code/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/wangtao/Documents/fantai/code/finclip-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2021-12-20 16:48:35.113009","version":"2.2.1"} \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index 310124c..e80a0ff 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -87,7 +87,7 @@ packages: path: ".." relative: true source: path - version: "2.34.5" + version: "2.34.9" path: dependency: transitive description: diff --git a/ios/Classes/Api/MOB_addWebExtentionApi.h b/ios/Classes/Api/MOB_addWebExtentionApi.h new file mode 100644 index 0000000..d33d50d --- /dev/null +++ b/ios/Classes/Api/MOB_addWebExtentionApi.h @@ -0,0 +1,16 @@ +// +// MOB_addWebExtentionApi.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOB_addWebExtentionApi : MOPBaseApi +@property(nonatomic, copy) NSString* name; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOB_addWebExtentionApi.m b/ios/Classes/Api/MOB_addWebExtentionApi.m new file mode 100644 index 0000000..ba81192 --- /dev/null +++ b/ios/Classes/Api/MOB_addWebExtentionApi.m @@ -0,0 +1,53 @@ +// +// MOB_addWebExtentionApi.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOB_addWebExtentionApi.h" +#import "MopPlugin.h" +#import + +@implementation MOB_addWebExtentionApi + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + NSLog(@"MOB_addWebExtentionApi"); + FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; + [[FATClient sharedClient] fat_registerWebApi:self.name handle:^(id param, FATExtensionApiCallback callback) { + NSLog(@"invoke webExtentionApi:"); + NSLog(@"%@",self.name); + NSLog(@"%@",param); + NSString* api = [@"webExtentionApi:" stringByAppendingString:self.name]; + [channel invokeMethod:api arguments:param result:^(id _Nullable result) { + NSLog(@"webExtentionApi reslut:%@",result); + // 先判断是否flutter发生错误 + BOOL isFlutterError = [result isKindOfClass:[FlutterError class]] || result == FlutterMethodNotImplemented; + if (isFlutterError) { + NSLog(@"webExtentionApi reslut:fail"); + callback(FATExtensionCodeFailure,nil); + return; + } + // 再判断回调是否为失败 + BOOL hasError = [[result allKeys] containsObject:@"errMsg"]; + if (hasError) { + NSString *errMsg = result[@"errMsg"]; + NSString *errPrefix = [NSString stringWithFormat:@"%@:fail", self.name]; + BOOL isFail = [errMsg hasPrefix:errPrefix]; + if (isFail) { + NSLog(@"webExtentionApi reslut:fail"); + callback(FATExtensionCodeFailure,nil); + return; + } + } + // 其他的按成功处理 + NSLog(@"webExtentionApi callback:%@",result); + callback(FATExtensionCodeSuccess,result); + }]; + + }]; + success(@{}); + +} +@end diff --git a/ios/Classes/Api/MOP_callJS.h b/ios/Classes/Api/MOP_callJS.h new file mode 100644 index 0000000..aa0c9ad --- /dev/null +++ b/ios/Classes/Api/MOP_callJS.h @@ -0,0 +1,18 @@ +// +// MOP_callJS.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_callJS : MOPBaseApi +@property (nonatomic, copy) NSString *eventName; +@property (nonatomic, copy) NSString *nativeViewId; +@property (nonatomic, copy) NSDictionary *eventData; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_callJS.m b/ios/Classes/Api/MOP_callJS.m new file mode 100644 index 0000000..07be0e4 --- /dev/null +++ b/ios/Classes/Api/MOP_callJS.m @@ -0,0 +1,28 @@ +// +// MOP_callJS.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOP_callJS.h" + +@implementation MOP_callJS + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + if (!self.eventData || !self.eventName || !self.nativeViewId) { + failure(@{@"errMsg": @"callJS:fail"}); + return; + } + + NSNumber *numberId = @(_nativeViewId.integerValue); + [[FATClient sharedClient].nativeViewManager sendEvent:_eventName nativeViewId:numberId detail:_eventData completion:^(id result, NSError *error) { + if (error) { + failure(@{@"errMsg": @"sendCustomEvent:fail"}); + } else { + success(result); + } + }]; +} +@end diff --git a/ios/Classes/Api/MOP_closeApplet.h b/ios/Classes/Api/MOP_closeApplet.h new file mode 100644 index 0000000..b87fb22 --- /dev/null +++ b/ios/Classes/Api/MOP_closeApplet.h @@ -0,0 +1,17 @@ +// +// MOP_closeApplet.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_closeApplet : MOPBaseApi +@property (nonatomic, copy) NSString *appletId; +@property (nonatomic, assign) BOOL animated; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_closeApplet.m b/ios/Classes/Api/MOP_closeApplet.m new file mode 100644 index 0000000..292f21a --- /dev/null +++ b/ios/Classes/Api/MOP_closeApplet.m @@ -0,0 +1,25 @@ +// +// MOP_closeApplet.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOP_closeApplet.h" +#import + +@implementation MOP_closeApplet + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + if (!self.appletId || self.appletId.length < 1) { + failure(@{@"errMsg": @"closeApplet:fail"}); + return; + } + [[FATClient sharedClient] closeApplet:self.appletId animated:_animated completion:^{ + success(@{}); + }]; + +} + +@end diff --git a/ios/Classes/Api/MOP_finishRunningApplet.h b/ios/Classes/Api/MOP_finishRunningApplet.h new file mode 100644 index 0000000..da8c676 --- /dev/null +++ b/ios/Classes/Api/MOP_finishRunningApplet.h @@ -0,0 +1,17 @@ +// +// MOP_finishRunningApplet.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_finishRunningApplet : MOPBaseApi +@property (nonatomic, copy) NSString appletId; +@property (nonatomic, assign) BOOL animated; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_finishRunningApplet.m b/ios/Classes/Api/MOP_finishRunningApplet.m new file mode 100644 index 0000000..3d1f6f5 --- /dev/null +++ b/ios/Classes/Api/MOP_finishRunningApplet.m @@ -0,0 +1,25 @@ +// +// MOP_finishRunningApplet.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOP_finishRunningApplet.h" + +@implementation MOP_finishRunningApplet + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + if (!self.appletId || self.appletId.length < 1) { + failure(@{@"errMsg": @"finishRunningApplet:fail"}); + return; + } + [[FATClient sharedClient] closeApplet:self.appletId animated:_animated completion:^{ + [[FATClient sharedClient] clearMemeryApplet:self.appletId]; + success(@{}); + }]; + +} + +@end diff --git a/ios/Classes/Api/MOP_registerExtensionApi.h b/ios/Classes/Api/MOP_registerExtensionApi.h index 0cd9fe5..e489f94 100644 --- a/ios/Classes/Api/MOP_registerExtensionApi.h +++ b/ios/Classes/Api/MOP_registerExtensionApi.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MOP_registerExtensionApi : MOPBaseApi -@property NSString* name; +@property(nonatomic, copy) NSString* name; @end diff --git a/ios/Classes/Api/MOP_removeApplet.h b/ios/Classes/Api/MOP_removeApplet.h new file mode 100644 index 0000000..eae034b --- /dev/null +++ b/ios/Classes/Api/MOP_removeApplet.h @@ -0,0 +1,16 @@ +// +// MOP_removeApplet.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_removeApplet : MOPBaseApi +@property (nonatomic, copy) NSString *appletId; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_removeApplet.m b/ios/Classes/Api/MOP_removeApplet.m new file mode 100644 index 0000000..5b11dcf --- /dev/null +++ b/ios/Classes/Api/MOP_removeApplet.m @@ -0,0 +1,32 @@ +// +// MOP_removeApplet.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOP_removeApplet.h" + +@implementation MOP_removeApplet + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + if (!self.appletId || self.appletId.length < 1) { + failure(@{@"errMsg": @"removeApplet:fail"}); + return; + } + FATAppletInfo *appletInfo = [[FATClient sharedClient] currentApplet]; + if (appletInfo && [appletInfo.appId isEqual:self.appletId]) { + [[FATClient sharedClient] closeApplet:self.appletId animated:NO completion:^{ + [[FATClient sharedClient] removeAppletFromLocalCache:self.appletId]; + success(@{}); + }]; + } else { + [[FATClient sharedClient] removeAppletFromLocalCache:self.appletId]; + success(@{}); + } + + + +} +@end diff --git a/ios/Classes/Api/MOP_sendCustomEvent.h b/ios/Classes/Api/MOP_sendCustomEvent.h new file mode 100644 index 0000000..2218594 --- /dev/null +++ b/ios/Classes/Api/MOP_sendCustomEvent.h @@ -0,0 +1,16 @@ +// +// MOP_sendCustomEvent.h +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_sendCustomEvent : MOPBaseApi +@property (nonatomic, strong) NSDictonary *eventData; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_sendCustomEvent.m b/ios/Classes/Api/MOP_sendCustomEvent.m new file mode 100644 index 0000000..4642b06 --- /dev/null +++ b/ios/Classes/Api/MOP_sendCustomEvent.m @@ -0,0 +1,28 @@ +// +// MOP_sendCustomEvent.m +// mop +// +// Created by 王滔 on 2021/12/21. +// + +#import "MOP_sendCustomEvent.h" + +@implementation MOP_sendCustomEvent + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + if (!self.eventData ) { + failure(@{@"errMsg": @"sendCustomEvent:fail"}); + return; + } + + [[FATClient sharedClient].nativeViewManager sendCustomEventWithDetail:self.eventData completion:^(id result, NSError *error) { + if (error) { + failure(@{@"errMsg": @"sendCustomEvent:fail"}); + } else { + success(result); + } + }]; + +} +@end diff --git a/ios/Classes/Api/MOP_setFinStoreConfigs.h b/ios/Classes/Api/MOP_setFinStoreConfigs.h new file mode 100644 index 0000000..d2b55ad --- /dev/null +++ b/ios/Classes/Api/MOP_setFinStoreConfigs.h @@ -0,0 +1,16 @@ +// +// MOP_setFinStoreConfigs.h +// mop +// +// Created by 王滔 on 2021/12/20. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_setFinStoreConfigs : MOPBaseApi +@property(nonatomic, strong) NSArray *storeConfigs; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_setFinStoreConfigs.m b/ios/Classes/Api/MOP_setFinStoreConfigs.m new file mode 100644 index 0000000..ffc562e --- /dev/null +++ b/ios/Classes/Api/MOP_setFinStoreConfigs.m @@ -0,0 +1,12 @@ +// +// MOP_setFinStoreConfigs.m +// mop +// +// Created by 王滔 on 2021/12/20. +// + +#import "MOP_setFinStoreConfigs.h" + +@implementation MOP_setFinStoreConfigs + +@end diff --git a/ios/Classes/MopPlugin.m b/ios/Classes/MopPlugin.m index 3f51f4e..669337a 100644 --- a/ios/Classes/MopPlugin.m +++ b/ios/Classes/MopPlugin.m @@ -91,7 +91,9 @@ static MopPlugin *_instance; return [[FATClient sharedClient] handleOpenURL:url]; } --(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler +- (BOOL)application:(UIApplication*)application + continueUserActivity:(NSUserActivity*)userActivity + restorationHandler:(void (^)(NSArray*))restorationHandler { if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { NSURL *url = userActivity.webpageURL; diff --git a/lib/mop.dart b/lib/mop.dart index 8c08066..2a7fa70 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ffi'; import 'package:flutter/services.dart'; import 'package:mop/api.dart'; @@ -8,6 +9,24 @@ typedef MopEventErrorCallback = void Function(dynamic event); typedef ExtensionApiHandler = Future Function(dynamic params); +class FinStoreConfig { + String sdkKey; //创建应用时生成的SDK Key + String sdkSecret; //创建应用时生成的SDK secret + String apiServer; //服务器地址,客户部署的后台地址 + + String apmServer; //apm统计服务器的地址,如果不填,则默认与apiServer一致 + int cryptType; //网络接口加密类型,默认为MD5 0:MD5 1:国密MD5 + String fingerprint; //SDK指纹 证联环境(https://open.fdep.cn/) 时必填,其他环境的不用填 + String + encryptServerData; //是否需要接口加密验证(初始化多服务器时使用)默认为不开启,当设置为YES时开启,接口返回加密数据并处理 + +} + +class FinAppletUIConfig { + Map navigationTitleTextAttributes; //导航栏的标题样式,目前支持了font + +} + class Mop { static final Mop _instance = new Mop._internal(); MethodChannel _channel; @@ -17,6 +36,8 @@ class Mop { Map _extensionApis = {}; + Map _webExtensionApis = {}; + factory Mop() { return _instance; } @@ -54,7 +75,13 @@ class Mop { if (handler != null) { return await handler(call.arguments); } - } else if (call.method.startsWith("extensionApi:")) {} + } else if (call.method.startsWith("webExtentionApi:")) { + final name = call.method.substring("webExtentionApi:".length); + final handler = _webExtensionApis[name]; + if (handler != null) { + return await handler(call.arguments); + } + } } /// @@ -246,4 +273,67 @@ class Mop { await _channel.invokeMapMethod("webViewBounces", {'bounces': bounces}); return; } + + //20211220新增Api + + //配置多个服务器 + Future setFinStoreConfigs(List configs) async {} + + //定制ui样式 + Future setUiConfig() async {} + + //自定义ua setUiConfig包含设置ua + Future setCustomWebViewUserAgent(String ua) async {} + + //支持指定服务器,启动参数,支持扫码打开小程序参数 之前已实现 启动参数 扫码打开小程序 + Future startApplet() async {} + + //定时批量更新小程序的数量 + Future setAppletIntervalUpdateLimit(int count) async {} + + //关闭小程序 + Future closeApplet(String appletId, bool animated) async { + await _channel.invokeMethod( + "closeApplet", {"appletId": appletId, "animated": animated}); + return; + } + + //结束小程序 关闭小程序 + Future finishRunningApplet(String appletId, bool animated) async { + await _channel.invokeMethod( + "finishRunningApplet", {"appletId": appletId, "animated": animated}); + return; + } + + //删除小程序 removeUsedApplet? 删掉缓存小程序包 + Future removeApplet(String appletId) async { + await _channel.invokeMethod("removeApplet", {"appletId": appletId}); + return; + } + + //设置小程序切换动画 安卓 + Future setActivityTransitionAnim() async {} + + //发送事件给小程序 + Future sendCustomEvent(Map eventData) async { + await _channel.invokeMethod("sendCustomEvent", {"eventData": eventData}); + return; + } + + //原生调用js + Future callJS(String eventName, String nativeViewId, + Map eventData) async { + await _channel.invokeMethod("callJS", { + "eventName": eventName, + "nativeViewId": nativeViewId, + "eventData": eventData + }); + return; + } + + //注册h5的拓展接口 + void addWebExtentionApi(String name, ExtensionApiHandler handler) { + _webExtensionApis[name] = handler; + _channel.invokeMethod("addWebExtentionApi", {"name": name}); + } }