7

dismissModalViewControllerAnimated is deprecated:first deprecated in iOS 6.0

  • My deployment target is 6.1 and Xcode is 5.1.
  • I want to remove this warning for 6.1 simulator.Is that Possible?????
  • If I will run that by selection in ios 5.1 then no warning.
mokagio
  • 16,391
  • 3
  • 51
  • 58
Jayaprada
  • 944
  • 8
  • 11
  • Possible duplicate ---> http://stackoverflow.com/questions/12445190/dismissmodalviewcontrolleranimated-deprecated – Maverick May 20 '14 at 10:21
  • possible duplicate of [Suppressing deprecated warnings in Xcode](http://stackoverflow.com/questions/2622017/suppressing-deprecated-warnings-in-xcode) – mylogon Jun 15 '15 at 21:10

4 Answers4

33

If I am correct, you simply want to suppress the warnings.

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

This is simply to suppress the warnings. In release builds, you should not use any deprecated functions.

EDIT: To suppress specific code that invokes warnings, use :

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

    [self dismissModalViewControllerAnimated:YES];

#pragma clang diagnostic pop
n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
  • better replace the deprecated code with the new one instead of supressing, simply replace the line with: [self dismissViewControllerAnimated:NO completion:nil];. This is the better option. – Bikram Thapa May 20 '14 at 10:48
  • Thanks for your answer.Is there any solution to hide warnings for that particular warnings.I don't want to supress all the warnings in that VC. – Jayaprada May 20 '14 at 10:49
  • See updated code. Also, unless your deployment target < 5.0, it's suggested to use the newer methods. They are available since iOS 5.x – n00bProgrammer May 20 '14 at 10:53
  • 1
    Thanks n00bProgrammer :) – Jayaprada May 20 '14 at 11:05
  • Excellent! I've been looking for this forever. – jestro Sep 27 '15 at 20:57
  • Apps are not rejected for using deprecated methods?! If they were 75% of all Apps out there would be ejected from the store ;) – Cliff Ribaudo Jan 09 '16 at 19:48
  • Yes, if it won't make your app crash, it will be never rejected! – softninja Oct 23 '16 at 13:38
  • Others have mentioned it, but need to mention it again - APPLE WILL NOT REJECT AN APP THAT USES DEPRECATED METHODS. – Gruntcakes Dec 21 '16 at 18:10
  • This works well for me. Because I am using Api that was deprecated in iOS9. But the newer API does not work with iOS 9. So there is no other solution but to suppress the warnings. – Robert J. Clegg Mar 15 '17 at 08:57
2

@n00bProgrammer thanks for your answer.

For those of us who still have code that supports earlier versions of iOS, the way I handle such old code is to wrap the older code in a version macro test as well as to suppress the compiler warnings that result.

Note that sometimes a deprecated item generates an implicit conversion warning that needs to be suppressed using "-Wconversion".

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        #pragma clang diagnostic ignored "-Wconversion"
        [controlCenter.label setLineBreakMode:UILineBreakModeWordWrap];
        #pragma clang diagnostic pop
    } else {
        [controlCenter.label setLineBreakMode:NSLineBreakByWordWrapping];
    }

You can find the version checker for older Objective-C code here: SYSTEM_VERSION_LESS_THAN()

You can find the version checker for new Swift and Objective-C code here: Swift and Objective-C version check past iOS 8

Community
  • 1
  • 1
neoscribe
  • 2,203
  • 1
  • 21
  • 18
1

use

[self presentViewController:loginController animated:YES completion:nil];

or

[self presentModalViewController:loginController animated:YES];

or

[self dismissViewControllerAnimated:NO completion:nil];
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

use thus the following code it works perfect

[self dismissViewControllerAnimated:YES completion:nil];

Tested and working fine.

:)

Prabhu Natarajan
  • 869
  • 1
  • 9
  • 13