FPCustomHandler is a helper class for Crashlytics to allow you run custom NSUncaughtExceptionHandler
or signal
handler when crash happened.
FPCustomHandler relies on the underlying implementation details of Crashlytics(version 3.8.4(121)), These may be changed in future Crashlytics releases. At your own risk to use it.
When you implement your custom handlers, please do take Async-Safe Functions into considerations.
Add pod 'Crashlytics-FPCustomHandler' to your Podfile
pod 'FPCrashHandler'
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//These methods should be called after start Crashlytics
FPCrashHandler.setupCustomExceptionHandler { exception in
NSLog("==> CustomNSExceptionCrashHandler called\n")
}
FPCrashHandler.setupCustomSignal { (status, info, context) in
NSLog("==> CustomSignalCrashHandler called\n");
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//These methods should be called after start Crashlytics
[FPCrashHandler setupCustomExceptionHandler:&CustomNSExceptionCrashHandler];
[FPCrashHandler setupCustomSignalHandler:&CustomSignalCrashHandler];
return YES;
}
static void CustomNSExceptionCrashHandler(NSException *exception)
{
NSLog(@"==> CustomNSExceptionCrashHandler called\n");
}
static void CustomSignalCrashHandler(int signo, siginfo_t *info, void *context)
{
NSLog(@"==> CustomSignalCrashHandler called\n");
}
//SIGABRT
abort();
//NSInvalidArgumentException
NSString* str = nil;
NSArray* array = @[str];
Or just present the debugOptionsAlert
on FPCrashHandler
.
You should run the demo app without Xcode's debbuger attached, then you can search the logs with "==>" here:
iOS Simulator -> Debug -> Open System Log (or press Cmd + / in iOS Simulator)
MIT