持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第25天,点击查看活动详情
五、自定义业务工具
在集成过程中会具体讲解
iOS接入指南
一、集成方式
官方接入文档
接入SDK可以通过Cocoapods的方式,目前外网资源有两种一种是github,一种是gitee,建议使用gitee外网资源接入,github下载比较慢。
【DoraemonKit/Core】必选,其他的库可以根据实际需要自主进行选择。
【DoraemonKit/WithGPS】模拟定位
【DoraemonKit/WithLoad】Load耗时
【DoraemonKit/WithMLeaksFinder】内存泄漏
【DoraemonKit/WithWeex】Weex相关
【DoraemonKit/WithLogger】NSLog、Lumberjack
二、使用DoraemonKit内置工具集的接入方式
#ifdef DEBUG
#import <DoraemonKit/DoraemonManager.h>
#endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef DEBUG
[[DoraemonManager shareInstance] installWithPid:@"productId"];//productId为在“平台端操作指南”中申请的产品id
#endif
}
三、添加自定义测试模块到Doraemon面板中
比如我们要在Doraemon面板中添加一个环境切换的功能。
第一步:首先创建一个继承于NSObject的类URDoraemonEnvPlugin(可自行命名),在该类中实现DoraemonPluginProtocol类中的协议,实现
- (void)pluginDidLoad;
- (void)pluginDidLoad:(NSDictionary *)itemData;
这两个方法,在这两个方法中,编写具体实现的业务逻辑即可。
第二步:在AppDelegate类的DoraemonManager初始化方法中,增加自定义功能代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self configDoraemonKit] ;
return YES;
}
- (void)configDoraemonKit {
[[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"nav_return" desc:@"用于app内部环境切换功能" pluginName:@"URDoraemonEnvPlugin" atModule:@"业务专区"];
[[DoraemonManager shareInstance] installWithPid:@"17af307be628d5959844c46395eb6d88"];
}
其中Title是新增功能的名称,icon是新增功能的图片,des是新增功能的描述,pluginName是实现具体业务逻辑的类名,module是新增功能所在模块的名称;
tips:目前也支持使用block方式接入自定义测试模块,使用方式如下:
[[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"nav_return" desc:@"用于app内部环境切换功能" pluginName:@"URDoraemonEnvPlugin(可以为空)" atModule:DoraemonLocalizedString(@"业务专区") handle:^(NSDictionary *itemData) {
NSLog(@"handle block plugin");
}];
DoraemonKit不仅适用于Object-C,也适用于Swift,在Swift语言中接入如下:
import UIKit
#if DEBUG
import DoraemonKit
#endif
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
DoraemonManager.shareInstance().install()
#endif
return true
}
}
以上所有操作均在debug模式下,一定不要在release模式进行操作。