iOS接入指南

一、集成方式

1.1: cocoapods依赖

Github外网资源
  1. pod 'DoraemonKit/Core', '~> 3.0.2', :configurations => ['Debug'] #必选
  2. pod 'DoraemonKit/WithGPS', '~> 3.0.2', :configurations => ['Debug'] #可选
  3. pod 'DoraemonKit/WithLoad', '~> 3.0.2', :configurations => ['Debug'] #可选
  4. pod 'DoraemonKit/WithLogger', '~> 3.0.2', :configurations => ['Debug'] #可选
  5. pod 'DoraemonKit/WithDatabase', '~> 3.0.2', :configurations => ['Debug'] #可选
  6. pod 'DoraemonKit/WithMLeaksFinder', '~> 3.0.2', :configurations => ['Debug'] #可选
  7. pod 'DoraemonKit/WithWeex', '~> 3.0.2', :configurations => ['Debug'] #可选

tip: 有些用户反映github下载资源太慢,可以选择下面这个方式安装

Gitee外网资源
  1. pod 'DoraemonKit/Core', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #必选
  2. pod 'DoraemonKit/WithLogger', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
  3. pod 'DoraemonKit/WithGPS', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
  4. pod 'DoraemonKit/WithLoad', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
  5. pod 'DoraemonKit/WithDatabase', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
  6. pod 'DoraemonKit/WithMLeaksFinder', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
  7. pod 'DoraemonKit/WithWeex', :git => "https://gitee.com/yixiangboy/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug'] #可选
内网资源(只适用于滴滴内部用户)
  1. pod 'DoraemonKit/Core', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  2. pod 'DoraemonKit/WithLogger', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  3. pod 'DoraemonKit/WithGPS', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  4. pod 'DoraemonKit/WithLoad', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  5. pod 'DoraemonKit/WithMLeaksFinder', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  6. pod 'DoraemonKit/WithDatabase', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']
  7. pod 'DoraemonKit/WithWeex', :git => "git@git.xiaojukeji.com:DoraemonKit/DoraemonKit.git", :tag => '3.0.2', :configurations => ['Debug']

Core subspec作为核心,必须引入,其他几个subspec你可以按照你的需求选择性接入。

如果你的日志是基于CocoaLumberjack,那你也可以引入WithLogger subspec。

如果你想使用模拟定位的功能,请单独接入WithGPS subspec。

如果你要集成Load耗时检测的话,那就请接入WithLoad subspec。

如果你要集成Weex的相关专项工具的话,那就请接入WithWeex subspec。

如果你要使用YYDebugDatabase在网页端调式数据库的话,那就请接入WithDatabase subspec。

如果你要使用MLeaksFinder查找内存泄漏的问题的话,那就请接入WithMLeaksFinder subspec。

1.2: Carthage依赖

  1. git "https://github.com/didi/DoraemonKit.git" "c3.0.0"

tip:只在Debug环境中进行集成,不要带到线上。有一些hook操作会污染线上代码。

二、使用DoraemonKit内置工具集的接入方式

在App启动的时候添加一下代码

  1. #ifdef DEBUG
  2. #import <DoraemonKit/DoraemonManager.h>
  3. #endif
  4. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  5. #ifdef DEBUG
  6. [[DoraemonManager shareInstance] installWithPid:@"productId"];//productId为在“平台端操作指南”中申请的产品id
  7. #endif
  8. }

通过以上步骤你就可以使用DorameonKit所有的内置工具集合。如果你想把自己与业务相关的一些工具代码加入到DoraemonKit中做统一管理的话,你可以按照3的步骤来做。

三、添加自定义测试模块到Doraemon面板中(非必要)

比如我们要在Doraemon面板中添加一个环境切换的功能。

第一步:新建一个类,实现DoraemonPluginProtocol协议中的pluginDidLoad方法,该方法就是以后点击Doraemon工具面板中“环境切换”按钮触发的事件。

比如以代驾司机端为例,点击按钮之后会进入环境切换页面。

  1. @implementation KDDoraemonEnvPlugin
  2. - (void)pluginDidLoad{
  3. [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDDoraemonSFViewController"];
  4. [[DoraemonManager shareInstance] hiddenHomeWindow];
  5. }
  6. @end

第二步:在Doraemon初始化的地方添加第一步中添加的“环境切换”插件

调用DoraemonManager的以下方法:

  1. [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"];

依次代表 集成到DoraemonKit面板中的标题,图标,描述,插件名称,和所属于的模块。

比如以代驾司机端为例:

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2. #ifdef DEBUG
  3. [self configDoraemonKit];
  4. #endif
  5. }
  6. //配置Doraemon工具集
  7. - (void)configDoraemonKit{
  8. [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"];
  9. [[DoraemonManager shareInstance] addH5DoorBlock:^(NSString *h5Url) {
  10. [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDWebViewController" withQuery:@{@"urlString":h5Url}];
  11. }];
  12. [[DoraemonManager shareInstance] installWithPid:@"productId"];
  13. }

tips:目前也支持使用block方式接入自定义测试模块,使用方式如下:

  1. [[DoraemonManager shareInstance] addPluginWithTitle:@"标题" icon:@"doraemon_default" desc:@"测试插件" pluginName:@"TestPlugin(可以为空)" atModule:DoraemonLocalizedString(@"业务工具") handle:^(NSDictionary *itemData) {
  2. NSLog(@"handle block plugin");
  3. }];

四、swift 接入方式

pod 同 OC 一样

swift 4.0 4.2 5.0 接入方式都一样

  1. import UIKit
  2. #if DEBUG
  3. import DoraemonKit
  4. #endif
  5. @UIApplicationMain
  6. class AppDelegate: UIResponder, UIApplicationDelegate {
  7. var window: UIWindow?
  8. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  9. // Override point for customization after application launch.
  10. #if DEBUG
  11. DoraemonManager.shareInstance().install()
  12. #endif
  13. return true
  14. }
  15. }

五、常见问题

1、DoKit2.0.0版本里面的appKey属性已经作废,大家在DoKit3.0.0及以上版本可以安全的删除。