这是捕获异常代码
#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];
}
出了什么问题?