我正在通过以下方法中止我的 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/