OpenApplus支持自定义API

2020-05-18  本文已影响0人  linwaiwai

OpenApplus将为专业版本以上客户提供的自定义API功能的。提供的自定义API功能的能够在IDE上编写mock接口,在客户端环境调用本地API。

使用的协议为:
wx.api.setNavigationBarTitle({title:"hello", success:function(){}, fail:function(){}});

在iOS端定义插件

#import <OpenApplus/OpenApplus.h>
NS_ASSUME_NONNULL_BEGIN

@interface OAPluginDemo :NSObject<OAPlugin>


/**
 api方法
 */
@property (nonatomic, copy) NSString *command;

/**
 请求参数
 */
@property (nonatomic, strong) NSDictionary *param;

@property (nonatomic, readonly, copy) id<OAPluginContext> context;


- (id)setupApiWithSuccess:(void(^_Null_unspecified)(NSDictionary<NSString *, id> * _Nonnull))success
failure:(void(^_Null_unspecified)(id _Nullable))failure
 cancel:(void(^_Null_unspecified)(void))cancel;

@end

NS_ASSUME_NONNULL_END
#import "OAPluginDemo.h"

@implementation OAPluginDemo

- (id)setupApiWithSuccess:(void(^_Null_unspecified)(NSDictionary<NSString *, id> * _Nonnull))success
failure:(void(^_Null_unspecified)(id _Nullable))failure
                   cancel:(void(^_Null_unspecified)(void))cancel{
    NSLog(@"do nothing");
    return nil;
}
@end

之后在进入小程序之前调用。

  [[OpenApplus apiExtension] registerApi:[OAPluginDemo class] name:@"setNavigationBarTitle"];
上一篇下一篇

猜你喜欢

热点阅读