.h文件
@interface CDVCommandQueue (CDVCommandQueueHook)
+ (void)hookUIApplication;
@end
.m文件
#import "CDVCommandQueue+CDVCommandQueueHook.h"
#import <objc/runtime.h>
#import "AppDelegate.h"
@implementation CDVCommandQueue (CDVCommandQueueHook)
+ (void)hookUIApplication
{
Method controlMethod = class_getInstanceMethod([CDVCommandQueue class], @selector(execute:));
Method hookMethod = class_getInstanceMethod([self class], @selector(hook_execute:));
method_exchangeImplementations(controlMethod, hookMethod);
}
// 调用插件后的处理
- (BOOL)hook_execute:(CDVInvokedUrlCommand*)command
{
// 操作历史存在内存中,最多只记录10条,如果闪退的话把最后10条调用记录和错误信息一块儿上报后台
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;<