-
-
Save aaronksaunders/dee39ad018c20f5b592b to your computer and use it in GitHub Desktop.
Working with TiExceptionHandler to better capture issues within my Appcelerator IOS Applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swap out the TiExceptionHandler classes for my own classes. | |
// will need to call the original method functionality at some point | |
-(void) resetErrorHandling | |
{ | |
[ComCiErrorHandlerModule swapMethod:@selector(reportScriptError:) | |
withMethod:@selector(reportScriptError:) | |
origClass:[TiExceptionHandler class] | |
newClass:[ComCiErrorHandlerModule class]]; | |
[ComCiErrorHandlerModule swapMethod:@selector(showScriptError:) | |
withMethod:@selector(showScriptError:) | |
origClass:[TiExceptionHandler class] | |
newClass:[ComCiErrorHandlerModule class]]; | |
[ComCiErrorHandlerModule swapMethod:@selector(reportException:withStackTrace:) | |
withMethod:@selector(reportScriptError:scriptError:) | |
origClass:[TiExceptionHandler class] | |
newClass:[ComCiErrorHandlerModule class]]; | |
} | |
// these are my replacement methods | |
- (void)showScriptError:(TiScriptError *)error | |
{ | |
NSLog(@"initializing NEW showScriptError: %@ ", [error description]); | |
} | |
- (void)reportScriptError:(TiScriptError *)scriptError | |
{ | |
NSLog(@"reportScriptError: %@ ", [scriptError description]); | |
} | |
- (void)reportException:(NSException *)exception withStackTrace:(NSArray *)stackTrace | |
{ | |
NSLog(@"initializing NEW reportException"); | |
} | |
// Here is the magic of Swizzling to get it done | |
+ (void)swapMethod:(SEL)origM withMethod:(SEL)newM origClass:(Class)origClass newClass:(Class)newClass { | |
Method origMethod = class_getInstanceMethod(origClass, origM); | |
Method newMethod = class_getInstanceMethod(newClass, newM); | |
if (class_addMethod(origClass, origM, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) { | |
class_replaceMethod(origClass, newM, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); | |
} else { | |
method_exchangeImplementations(origMethod, newMethod); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment