如果我们继承了UIApplication,就可以捕捉到应用程序发生的各种事件。首先,像下面这样实现你的 main 方法。
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, @"MyApplication", @"MyAppDelegate");
[pool release];
return retVal;
}
UIApplicationMain 函数的第三个参数中放入继承的UIApplication类名称。第四个参数是委托类(UIApplicationDelegate)的名称。
只要你重载了该类中的函数,就可以hook许多有用的事件。比如下面的方法:
- (void)applicationWillSuspend;
我们可以重载一些私有的API,来实现一些特殊的处理。你可以查看这里得到更多信息。
比如点击了状态条的事件。
- (void)statusBarMouseDown:(struct __GSEvent *)fp8;
- (void)statusBarMouseDragged:(struct __GSEvent *)fp8;
- (void)statusBarMouseUp:(struct __GSEvent *)fp8;