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;
}
Is there a reason the super class method is being called first? If you are intercepting, you should be calling it last.
That might be your problem. I also override sendEvent to intercept all events to my application and have no issues.
If you call the super method first it will pass it to all UIResponders that may eventually eat your event resulting in the EXEC_BAD_ACCESS. Furthermore as DavidNeiss suggests eliminate the lines below the super call. If you still receive the bad access signal its likely another view or controller down the line causing it. You'll need to stack trace to find out where it is.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With