iOS Version Checking gives warning

167 Views Asked by At

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];
  }
3

There are 3 best solutions below

0
On

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];
}
3
On

You can enable / disable warning with pragma into your code, but they are not very friendly to use. And i don't remember the specific pragma for this kind of warning. But some guys here will told you.

By the way you can use a simple

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

will do the trick

0
On

I had mistakenly set the deployment target to 6.0. So it was showing the mentioned warning message. No warning message after I changed the deployment target to 4.3(which I need to support). Thanks for the answers!.