使用 UIAlertView 以编程方式退出 iOS 应用程序 [英] Quit iOS Application Programmatically with UIAlertView

查看:18
本文介绍了使用 UIAlertView 以编程方式退出 iOS 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm aborting my iOS Application by below methods

-(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 应用程序吗?

Shall I do this to quit my iOS Application programmatically?

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

Will this abort() method leads to reject my app?

谢谢!

推荐答案

参见 QA1561:

问:如何以编程方式退出我的 iOS 应用程序?

Q: How do I programmatically quit my iOS application?

A:没有提供用于优雅终止 iOS 的 API申请.

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

在 iOS 中,用户按下主页按钮关闭应用程序.应该您的应用程序有条件,它不能提供其预期的功能,推荐的方法是显示警报指示问题性质和可能操作的用户用户可以采取——打开 WiFi,启用定位服务,等.允许用户自行终止应用程序自由裁量权.

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.

这篇关于使用 UIAlertView 以编程方式退出 iOS 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆