This is catch the exception code
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NdUncaughtExceptionHandler : NSObject {
}
+ (void)setDefaultHandler;
@end
-
#import "UncaughtExceptionHandler.h"
void UncaughtExceptionHandler(NSException *exception) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
@implementation NdUncaughtExceptionHandler
+ (void)setDefaultHandler {
NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler);
}
@end
Call the method is NdUncaughtExceptionHandler.setDefaultHandler()
, but does not work in the swift.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
NdUncaughtExceptionHandler.setDefaultHandler()
}
It can work in the Objecttive-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[NdUncaughtExceptionHandler setDefaultHandler];
}
What went wrong?