App优雅闪退如同按了home键

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"友好提示" message:@"发现新的补丁,是否需要安装补丁?安装完需重启应用,请选择..." preferredStyle:(UIAlertControllerStyleAlert)];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"更新补丁" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            dispatch_async(dispatch_get_main_queue(), ^{
                //私有api 回到桌面如同按了Home键
                [[UIApplication sharedApplication] performSelector:@selector(suspend)];
                //加点延时等动画结束再闪退
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.26 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    exit(-1);
                });
            });
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"下次再说" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [self.window.rootViewController presentViewController:alertVC animated:YES completion:nil];
posted @ 2023-06-16 20:07  CoderWGB  阅读(4)  评论(0编辑  收藏  举报