IOS version check gives warning

In my application, I need to submit a view controller. The 6.0 method for presenting a view controller is presentViewController: animated: completion :. I also want to support 4.3. In 4.3, the method to be called is ModalViewController: animated :. So I use responsesToSelector: to find out if this method is supported. But when I compile the application for version 6.0, it gives a warning message like

presentModalViewController: animated: deprecated: deprecated first in iOS 6.0

Does anyone know how to get rid of this warning. I also do not have a 4.3 device to check if it works. I need to assume that the code I'm writing should work on 4.3.

  if([myViewController respondsToSelector:@selector(presentModalViewController:animated:)]){
      [myViewController presentModalViewController:anotherViewController animated:YES];
  }else{
      [myViewController presentViewController:anotherViewController animated:YES completion:nil];
  }
+5
source share
3 answers

you can do the opposite check for respondsToSelector, this can help, and actually this is the way if you support older versions :)

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
    [self presentViewController:anotherViewController animated:YES completion:nil];
} else {
    [self presentModalViewController:anotherViewController animated:YES];
}
+3
source

You can enable / disable the warning using pragma in your code, but they are not very friendly to use. And I do not remember a specific pragma for such a warning. But some guys here will tell you.

By the way, you can use simple

[id performSelector:<#(SEL)#> withObject:<#(id)#>]

will do the trick

+1
source

6.0. , . , 4.3 ( ). !

0

All Articles