DoKitAppDelegate.m 10.0 KB
Newer Older
Y
yixiang 已提交
1 2 3 4 5 6 7 8
//
//  AppDelegate.m
//  DoraemonKitDemo
//
//  Created by yixiang on 2017/12/11.
//  Copyright © 2017年 yixiang. All rights reserved.
//

9
#import "DoKitAppDelegate.h"
Y
yixiang 已提交
10 11
#import <DoraemonKit/DoraemonKit.h>
#import "DoraemonDemoHomeViewController.h"
Y
yixiangboy 已提交
12
#import "DoraemonTimeProfiler.h"
Y
yixiang 已提交
13
//#import <CocoaLumberjack/CocoaLumberjack.h>
Y
yixiangboy 已提交
14
#import "DoraemonUtil.h"
Y
yixiangboy 已提交
15
#import "SDImageWebPCoder.h"
R
Rake Yang 已提交
16
#import <DoraemonKit/DoraemonAppInfoViewController.h>
M
mizikoi53 已提交
17
#import <fmdb/FMDB.h>
Y
yixiang 已提交
18

19 20 21 22 23 24
#if __has_include(<FBRetainCycleDetector/FBRetainCycleDetector.h>)
#define XXX 1
#else
#define XXX 2
#endif

25
@interface DoKitAppDelegate ()
Y
yixiang 已提交
26 27 28

@end

29
@implementation DoKitAppDelegate
Y
yixiang 已提交
30 31 32

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
Y
fix  
yixiangboy 已提交
33
    //[DoraemonTimeProfiler startRecord];
Y
yixiangboy 已提交
34
    
Y
yixiangboy 已提交
35 36 37
//    id a = [[NSObject alloc] init];
//    [a b];
    
Y
yixiang 已提交
38 39 40 41 42 43
    //[[self class] handleCCrashReportWrap];
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

    for (int i=0; i<10; i++) {
        //DDLogInfo(@"点击添加埋点11111");
    }
Y
yixiangboy 已提交
44
    [[DoraemonManager shareInstance] addPluginWithTitle:DoraemonDemoLocalizedString(@"测试插件") icon:@"doraemon_default" desc:DoraemonDemoLocalizedString(@"测试插件") pluginName:@"TestPlugin" atModule:DoraemonDemoLocalizedString(@"业务工具")];
E
Eric Wu 已提交
45

Y
yixiangboy 已提交
46
    [[DoraemonManager shareInstance] addPluginWithTitle:DoraemonDemoLocalizedString(@"block方式加入插件") icon:@"doraemon_default" desc:@"测试插件" pluginName:@"pluginName" atModule:DoraemonDemoLocalizedString(@"业务工具") handle:^(NSDictionary *itemData) {
E
Eric Wu 已提交
47 48
        NSLog(@"handle block plugin");
    }];
49 50
    
    [[DoraemonManager shareInstance] addPluginWithTitle:@"自定图标" image:[UIImage imageNamed:@"zhaoliyin"] desc:@"自定义图标" pluginName:@"自定图标" atModule:DoraemonDemoLocalizedString(@"业务工具") handle:nil];
E
Eric Wu 已提交
51

Y
yixiangboy 已提交
52 53
    //测试 a49842eeebeb1989b3f9565eb12c276b
    //线上 749a0600b5e48dd77cf8ee680be7b1b7
54
    //[DoraemonManager shareInstance].pId = @"749a0600b5e48dd77cf8ee680be7b1b7";
Y
yixiang 已提交
55
    [[DoraemonManager shareInstance] addStartPlugin:@"StartPlugin"];
56 57
    [DoraemonManager shareInstance].bigImageDetectionSize = 10 * 1024;//大图检测只检测10K以上的
    [DoraemonManager shareInstance].startClass = @"DoKitAppDelegate";
Y
yixiangboy 已提交
58
    //[DoraemonManager shareInstance].autoDock = NO;
59
    [[DoraemonManager shareInstance] installWithPid:@"749a0600b5e48dd77cf8ee680be7b1b7"];
60
    //[[DoraemonManager shareInstance] installWithStartingPosition:CGPointMake(66, 66)];
Y
yixiang 已提交
61 62 63 64
    
    [[DoraemonManager shareInstance] addANRBlock:^(NSDictionary *anrDic) {
        NSLog(@"anrDic == %@",anrDic);
    }];
65

Y
yixiangboy 已提交
66 67
    [[DoraemonManager shareInstance] addH5DoorBlock:^(NSString *h5Url) {
        NSLog(@"使用自带容器打开H5链接: %@",h5Url);
M
moliya 已提交
68
        
Y
yixiangboy 已提交
69 70 71 72 73 74 75
    }];
    
    [[DoraemonManager shareInstance] addWebpHandleBlock:^UIImage * _Nullable(NSString * _Nonnull filePath) {
        NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
        UIImage *image = [[SDImageWebPCoder sharedCoder] decodedImageWithData:data options:nil];
        return image;
    }];
EyreFree's avatar
EyreFree 已提交
76 77 78 79 80
    // 例子:移除 GPS Mock
//    [[DoraemonManager shareInstance] installWithCustomBlock:^{
//        [[DoraemonManager shareInstance] removePluginWithPluginName:@"DoraemonGPSPlugin" atModule:@"常用工具"];
//    }];

Y
yixiang 已提交
81 82 83 84 85 86 87 88 89 90 91
    for (int i=0; i<10; i++) {
       // DDLogInfo(@"点击添加埋点22222");
    }
    
    
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    DoraemonDemoHomeViewController *homeVc = [[DoraemonDemoHomeViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
Y
fix  
yixiangboy 已提交
92 93 94
    
    NSArray *array = @[];
    NSLog(@"%@",[array description]);
Y
yixiangboy 已提交
95
    
Y
fix  
yixiangboy 已提交
96
    //[DoraemonTimeProfiler stopRecord];
Y
yixiangboy 已提交
97
    
98
    [self test];
M
mizikoi53 已提交
99 100
    
    [self createTestDatabase];
101
    
Y
yixiang 已提交
102 103 104
    return YES;
}

105 106
- (void)test{
    [self test2];
R
Rake Yang 已提交
107 108 109 110 111 112
    
    DoraemonAppInfoViewController.customAppInfoBlock = ^(NSMutableArray<NSDictionary *> *appInfos) {
        [appInfos addObject:@{@"title": @"Build Time", @"value": @"2020-05-21 11:29:22"}];
        [appInfos addObject:@{@"title": @"Commit", @"value": @"1ffa9c6"}];
        [appInfos addObject:@{@"title": @"Branch", @"value": @"version/1.2.0"}];
    };
113 114 115
}

- (void)test2{
Y
yixiangboy 已提交
116 117 118 119 120
    NSDictionary *dic = @{
        @"name":@"yixiang"
    }.mutableCopy;
    [dic setValue:@"caoweoweo" forKey:@"name"];
    NSLog(@"a == %@",dic);
121 122
}

M
mizikoi53 已提交
123 124 125 126 127 128 129 130 131
- (void)createTestDatabase {
    NSString *rootPath = NSHomeDirectory();
    NSString *dBPath = [NSString stringWithFormat:@"%@/Documents/dokit_test_database.sqlite", rootPath];
    FMDatabase *db;
    if (![[NSFileManager defaultManager] fileExistsAtPath:dBPath]) {
        db = [FMDatabase databaseWithPath:dBPath];
        db.shouldCacheStatements = YES;
        
        if ([db open]) {
M
mizikoi53 已提交
132
            NSString *sql_1 = @"CREATE TABLE IF NOT EXISTS dokit_records_table (id INTEGER PRIMARY KEY, record TEXT, record_2 INTEGER);";
M
mizikoi53 已提交
133 134
            [db executeUpdate:sql_1];
            
M
mizikoi53 已提交
135 136
//            NSString *sql_2 = @"CREATE TABLE IF NOT EXISTS dokit_records_table_2 (id_2 INTEGER PRIMARY KEY AUTOINCREMENT, record_2 TEXT);";
//            [db executeUpdate:sql_2];
M
mizikoi53 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
            
//            NSString *sql_3 = @"SELECT * FROM sqlite_master WHERE type='table' ORDER BY name;";
//            FMResultSet *set = [db executeQuery:sql_3];
//            while ([set next]) {
//                NSString *name = [set stringForColumnIndex:1];
//                NSLog(@"-=-=-=- name = %@", name);
//            }

            [db close];
        }
    }
}

Y
yixiang 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
void uncaughtExceptionHandler(NSException*exception){
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@",[exception callStackSymbols]);
    // Internal error reporting
}

+(void) handleCCrashReportWrap{    
//    PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: PLCrashReporterSignalHandlerTypeMach symbolicationStrategy: PLCrashReporterSymbolicationStrategyAll];
//    PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration:config];
//
//    NSError *error;
//
//    // Check if we previously crashed
//    if ([crashReporter hasPendingCrashReport])
//        [self handleCCrashReport:crashReporter ];
//
//    // Enable the Crash Reporter
//    if (![crashReporter enableCrashReporterAndReturnError: &error])
//        NSLog(@"Warning: Could not enable crash reporter: %@", error);
}

//+ (void) handleCCrashReport:(PLCrashReporter * ) crashReporter{
//    NSData *crashData;
//    NSError *error;
//    
//    // Try loading the crash report
//    crashData = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
//    if (crashData == nil) {
//        NSLog(@"Could not load crash report: %@", error);
//        [crashReporter purgePendingCrashReport];
//        return;
//    }
//    
//    // We could send the report from here, but we'll just print out
//    // some debugging info instead
//    PLCrashReport *report = [[PLCrashReport alloc] initWithData: crashData error: &error] ;
//    
//    if (report == nil) {
//        NSLog(@"Could not parse crash report");
//        [crashReporter purgePendingCrashReport];
//        return;
//    }
//    
//    //    NSLog(@"Crashed on %@", report.systemInfo.timestamp);
//    //    NSLog(@"Crashed with signal %@ (code %@, address=0x%" PRIx64 ")", report.signalInfo.name,
//    //          report.signalInfo.code, report.signalInfo.address);
//    
//    // Purge the report
//    [crashReporter purgePendingCrashReport];
//    
////    *     //上传--这后面的代码是我加的.
//       NSString *humanText = [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS];
//    NSLog(@"yixiang crash == %@",humanText);
////    *
////    *     [self uploadCrashLog:@"c crash" crashContent:humanText withSuccessBlock:^{
////        *     }];//uploadCrashLog这个函数是把log文件上传服务器的,请自行补充哈;还可以写入沙盒,供自己就地查看,下面是写入沙盒的代码
////    *
////    *     NSString * documentDic = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES).firstObject;
////    *     NSString * fileName = [documentDic stringByAppendingPathComponent:@"1.crash"];
////    *     NSError * err = nil;
////    *     [humanText writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:&err];
////    return;
//
//}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end