小程序代理配置

master
kangxuyao 2020-04-27 18:55:36 +08:00
parent 717507f7ea
commit b860cb8a93
3 changed files with 14 additions and 3 deletions

View File

@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface MOPAppletDelegate : NSObject<FATAppletDelegate> @interface MOPAppletDelegate : NSObject<FATAppletDelegate>
+ (instancetype)instance;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -10,11 +10,21 @@
@implementation MOPAppletDelegate @implementation MOPAppletDelegate
+ (instancetype)instance
{
static MOPAppletDelegate *_instance;
static dispatch_once_t once;
dispatch_once(&once, ^{
_instance = [[self alloc] init];
});
return _instance;
}
- (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion - (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion
{ {
NSLog(@"forwardAppletWithInfo:%@",contentInfo); NSLog(@"forwardAppletWithInfo:%@",contentInfo);
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
[channel invokeMethod:@"extensionApi:forwardApplet" arguments:contentInfo result:^(id _Nullable result) { [channel invokeMethod:@"extensionApi:forwardApplet" arguments:@{@"appletInfo":contentInfo} result:^(id _Nullable result) {
if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ]) if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ])
{ {
completion(FATExtensionCodeFailure,nil); completion(FATExtensionCodeFailure,nil);

View File

@ -15,8 +15,7 @@
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel - (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{ {
NSLog(@"MOP_registerAppletHandler"); NSLog(@"MOP_registerAppletHandler");
[[FATClient sharedClient] setDelegate:[[MOPAppletDelegate alloc] init]]; [FATClient sharedClient].delegate = [MOPAppletDelegate instance];
} }
@end @end