您的位置:首页 > 移动开发 > IOS开发

保证IOS程序始终不死

2016-07-26 16:36 453 查看
void handleException(NSException *exception)

{

    [[UIApplication sharedApplication].delegate performSelector:@selector(handle)];

}

- (void)handle

{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"哈哈" message:@"傻逼了把" delegate:self cancelButtonTitle:@"好的"
otherButtonTitles:nil, nil];

    [alertView show];

    

    // 重新启动RunLoop

    [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSDefaultRunLoopMode];

    [[NSRunLoop currentRunLoop] run];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    NSLog(@"-------点击了好的");

//    exit(0);

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

    //
设置捕捉异常的回调

    NSSetUncaughtExceptionHandler(handleException);

    

    return YES;

}

重启一个RunLoop循环保证程序不死
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: