Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Version Checking gives warning

In my app I need to present a view controller. The 6.0 method for presenting a view controller is presentViewController:animated:completion:. I want to support 4.3 also. In 4.3 the method to be called is presentModalViewController:animated:. So I use respondsToSelector: to find out whether the method is supported. But when I compile the app for 6.0 it gives warning message as

presentModalViewController:animated: is deprecated: first deprecated in iOS 6.0

Can anyone know how to get rid of this warning. I also do not have 4.3 device to test whether it works. I need to assume that the code I write should work on 4.3.

  if([myViewController respondsToSelector:@selector(presentModalViewController:animated:)]){
      [myViewController presentModalViewController:anotherViewController animated:YES];
  }else{
      [myViewController presentViewController:anotherViewController animated:YES completion:nil];
  }
like image 467
saikamesh Avatar asked Oct 04 '22 19:10

saikamesh


1 Answers

you could make check opposite for respondsToSelector it might help, and this is the way to go actually if you are supporting older versions:)

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
    [self presentViewController:anotherViewController animated:YES completion:nil];
} else {
    [self presentModalViewController:anotherViewController animated:YES];
}
like image 178
nsgulliver Avatar answered Oct 13 '22 12:10

nsgulliver