feat: 新增Api的部分定义和实现
parent
f9a5f9d079
commit
c89aaa91cd
|
@ -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"}
|
||||
{"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"}
|
|
@ -87,7 +87,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "2.34.5"
|
||||
version: "2.34.9"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// MOB_addWebExtentionApi.m
|
||||
// mop
|
||||
//
|
||||
// Created by 王滔 on 2021/12/21.
|
||||
//
|
||||
|
||||
#import "MOB_addWebExtentionApi.h"
|
||||
#import "MopPlugin.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOB_addWebExtentionApi
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _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
|
|
@ -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
|
|
@ -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<NSString *,id> * _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
|
|
@ -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
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// MOP_closeApplet.m
|
||||
// mop
|
||||
//
|
||||
// Created by 王滔 on 2021/12/21.
|
||||
//
|
||||
|
||||
#import "MOP_closeApplet.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_closeApplet
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _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
|
|
@ -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
|
|
@ -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<NSString *,id> * _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
|
|
@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface MOP_registerExtensionApi : MOPBaseApi
|
||||
|
||||
@property NSString* name;
|
||||
@property(nonatomic, copy) NSString* name;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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<NSString *,id> * _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
|
|
@ -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
|
|
@ -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<NSString *,id> * _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
|
|
@ -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
|
|
@ -0,0 +1,12 @@
|
|||
//
|
||||
// MOP_setFinStoreConfigs.m
|
||||
// mop
|
||||
//
|
||||
// Created by 王滔 on 2021/12/20.
|
||||
//
|
||||
|
||||
#import "MOP_setFinStoreConfigs.h"
|
||||
|
||||
@implementation MOP_setFinStoreConfigs
|
||||
|
||||
@end
|
|
@ -91,7 +91,9 @@ static MopPlugin *_instance;
|
|||
return [[FATClient sharedClient] handleOpenURL:url];
|
||||
}
|
||||
|
||||
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
|
||||
- (BOOL)application:(UIApplication*)application
|
||||
continueUserActivity:(NSUserActivity*)userActivity
|
||||
restorationHandler:(void (^)(NSArray*))restorationHandler
|
||||
{
|
||||
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||
NSURL *url = userActivity.webpageURL;
|
||||
|
|
92
lib/mop.dart
92
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<String, dynamic> navigationTitleTextAttributes; //导航栏的标题样式,目前支持了font
|
||||
|
||||
}
|
||||
|
||||
class Mop {
|
||||
static final Mop _instance = new Mop._internal();
|
||||
MethodChannel _channel;
|
||||
|
@ -17,6 +36,8 @@ class Mop {
|
|||
|
||||
Map<String, ExtensionApiHandler> _extensionApis = {};
|
||||
|
||||
Map<String, ExtensionApiHandler> _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<void> setFinStoreConfigs(List<FinStoreConfig> configs) async {}
|
||||
|
||||
//定制ui样式
|
||||
Future<void> setUiConfig() async {}
|
||||
|
||||
//自定义ua setUiConfig包含设置ua
|
||||
Future<void> setCustomWebViewUserAgent(String ua) async {}
|
||||
|
||||
//支持指定服务器,启动参数,支持扫码打开小程序参数 之前已实现 启动参数 扫码打开小程序
|
||||
Future<void> startApplet() async {}
|
||||
|
||||
//定时批量更新小程序的数量
|
||||
Future<void> setAppletIntervalUpdateLimit(int count) async {}
|
||||
|
||||
//关闭小程序
|
||||
Future<void> closeApplet(String appletId, bool animated) async {
|
||||
await _channel.invokeMethod(
|
||||
"closeApplet", {"appletId": appletId, "animated": animated});
|
||||
return;
|
||||
}
|
||||
|
||||
//结束小程序 关闭小程序
|
||||
Future<void> finishRunningApplet(String appletId, bool animated) async {
|
||||
await _channel.invokeMethod(
|
||||
"finishRunningApplet", {"appletId": appletId, "animated": animated});
|
||||
return;
|
||||
}
|
||||
|
||||
//删除小程序 removeUsedApplet? 删掉缓存小程序包
|
||||
Future<void> removeApplet(String appletId) async {
|
||||
await _channel.invokeMethod("removeApplet", {"appletId": appletId});
|
||||
return;
|
||||
}
|
||||
|
||||
//设置小程序切换动画 安卓
|
||||
Future<void> setActivityTransitionAnim() async {}
|
||||
|
||||
//发送事件给小程序
|
||||
Future<void> sendCustomEvent(Map<String, dynamic> eventData) async {
|
||||
await _channel.invokeMethod("sendCustomEvent", {"eventData": eventData});
|
||||
return;
|
||||
}
|
||||
|
||||
//原生调用js
|
||||
Future<void> callJS(String eventName, String nativeViewId,
|
||||
Map<String, dynamic> 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});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue