Last active
August 29, 2015 14:01
-
-
Save siberianisaev/7de64c5cb57d5a3997ae to your computer and use it in GitHub Desktop.
Exception Handler
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
#import <Foundation/Foundation.h> | |
@interface ExceptionHandler : NSObject | |
+ (void)startHandleExceptions; | |
@end |
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
#import "ExceptionHandler.h" | |
@implementation ExceptionHandler | |
+ (ExceptionHandler *)handler | |
{ | |
static ExceptionHandler *sharedInstance = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[ExceptionHandler alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
/** | |
Call this method in App Delegate -application:didFinishLaunchingWithOptions: | |
*/ | |
+ (void)startHandleExceptions | |
{ | |
[[ExceptionHandler handler] setExceptionHandler]; | |
} | |
static void uncaughtExceptionHandler(NSException *exception){ | |
NSLog(@"Crash: %@", exception); | |
NSLog(@"Stack trace: %@", [exception callStackSymbols]); | |
//[Flurry logError:@"Uncaught exception handled." message:@"App crash registered!" exception:exception]; | |
} | |
- (void)setExceptionHandler | |
{ | |
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment