I'm trying subclass UIApplication to catch all touch event, this is used to see if user is afk or not. Anyway it works great first time you launch the application. If you put it in background and open it again 2 times then it crashes. I have no idea what causes this. I'm getting EXEC_BAD_ACCESS on [super sendEvent:event];
My Subclass MyUI:
@implementation MyUI
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event]; // <-- EXEC_BAD_ACCESS
if (event.type == UIEventTypeTouches) {
UITouch *touch = [event allTouches].anyObject;
if (touch.phase == UITouchPhaseBegan) {
// Calling some methods
}
}
}
@end
Main.m
int main(int argc, char *argv[])
{
NSString* appClass = @"MyUI";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, appClass, nil);
[pool release];
return retVal;
}
To get exact reason for EXEC_BAD_ACCESS use nszombieenabled in your application. This link will guide you for using it. http://iosdevelopertips.com/debugging/tracking-down-exc_bad_access-errors-with-nszombieenabled.html