ios - 使用 UIAlertView 以编程方式退出 iOS 应用程序

标签 ios uialertview abort

我正在通过以下方法中止我的 iOS 应用程序

-(void)cancelSelected
{
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure you want to exit?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];

    [alert show];

    alert = nil;
}

方法一:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex)
        abort();
}

方法二:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex)
        [NSException raise:@"Disagree terms and conditions." format:@"Quit, Cancel"];
}

我应该这样做以编程方式退出我的 iOS 应用程序吗?

这个 abort() 方法会拒绝我的应用吗?

谢谢!

最佳答案

参见 QA1561 :

Q: How do I programmatically quit my iOS application?

A: There is no API provided for gracefully terminating an iOS application.

In iOS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

关于ios - 使用 UIAlertView 以编程方式退出 iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23391706/

相关文章:

ios - 无法确定弹出箭头方向

iphone - 从 UIAlertView 获取文本

ios - 我可以在 ios sdk 的警报 View 中添加单选按钮吗?

ios - Apple 允许自定义 UIAlertView 吗?

bash - 脚本终止后删除文件

android - 可以在应用程序中查看 jQuery/Javascript 吗?

ios - 列表中列表的 RestKit 对象映射

objective-c - HTML img 标签中使用的 Core Data 的 iOS Assets 路径

c - MPI_Abort() 与 exit()

c# - 完成后我应该如何处理线程?离开它还是中止它?