swift - NSSetUncaughtExceptionHandler无法正常工作,但可以在OC中工作

时间:2015-06-24 09:18:33

标签: ios swift exception

这是捕获异常代码

#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

调用方法为NdUncaughtExceptionHandler.setDefaultHandler(),但在swift中不起作用。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        NdUncaughtExceptionHandler.setDefaultHandler()
}

它可以在Objecttive-C

中工作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [NdUncaughtExceptionHandler setDefaultHandler];
}

出了什么问题?

0 个答案:

没有答案