“应用程序试图把目标一零模态视图控制器”上iOS7错误及以下

问题描述:

嗨,我是老迁移项目的iOS我从辅助类ApiManager.m(网络电话)“应用程序试图把目标一零模态视图控制器”上iOS7错误及以下

我新的代码行得到这个错误
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NO_INTERNET_ERROR_TITLE message:TRACKED_ITEM_NOT_FOUND_ERROR preferredStyle:UIAlertControllerStyleAlert]; 
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
[alert addAction:ok]; 
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil]; 

错误是:

016-08-16 13:52:49.955新邮政[967:60B] ***终止应用程序由于 未捕获的异常 'NSInvalidArgumentException',原因:“应用程序 试图在目标上提供一个无模式视图控制器。'

这个问题只发生在iOS 7及以下版本。从版本8和以上没有错。如何解决这个问题?任何帮助非常感谢。谢谢!

按照iOS版版本你应该使用UIAlertView和UIAlertController:

if(SYSTEM_VERSION_LESS_THAN(@"8.0")) 
{ 
    alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Invalid Coupon." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
} 
     else 
     { 
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Invalid Coupon." preferredStyle:UIAlertControllerStyleAlert]; 


     UIAlertAction *okAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"OK", @"OK action") 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction *action) 
            { 

            }]; 

     [alertController addAction:okAction]; 

     [self presentViewController:alertController animated:YES completion:nil]; 
    } 

的问题发生在IOS 7,因为UIAlertController作为医生说 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/

可提供的iOS 8.0和后期

对于iOS 7,你需要使用UIAlertView

+0

感谢您的信息。我们现在还应该支持IOS 7吗?我应该把发展目标移到8.0吗? –

+0

如果您停止支持iOS 7的用户,我想是的,您可以将开发目标更改为8.0 – iSashok

+0

我的意思是我们应该保留代码以支持IOS7还是完全停止支持(将目标更改为8.0)?在2016年8月? iOS 7有很多用户吗? –