监测所有通知

我们都知道有很多的api是私有的,同时有很多通知也是没有暴露出来的,有时候我们找到了重现的规律,却没办法找到重现的triger,可以通过监听所有通知并重现来定位该通知.

[[NSNotificationCenter defaultCenter] addObserverForName:nil
  object:nil
  queue:nil
  usingBlock:^(NSNotification* notification) {
    NSLog(@"Notification:\n"\
    "name: %@\n"\
    "object: %@\n"\
    "userInfo: %@",
    notification.name,
    notification.object,
    notification.userInfo);
  }];
  

没有详细信息的crash异常捕捉

这个很常见了,直接把main函数try catch即可,个人非常喜欢,简单暴力

@try {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    } @catch (NSException *exception) {
        NSLog(@"main------%@", [exception callStackSymbols]);
    }

有人推荐在didFinishLaunchingWithOptions中设置异常回调也可以

void handleException(NSException *exception)
{
    NSMutableDictionary *info = [NSMutableDictionary dictionary];
    info[@"callStack"] = [exception callStackSymbols];
    info[@"name"] = [exception name];
    info[@"reason"] = [exception reason];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // 设置回调
    NSSetUncaughtExceptionHandler(handleException);
    return YES;
}

标签: iOS, 崩溃, 异常, try catch, main

添加新评论