just_another_coder
just_another_coder

Reputation: 1166

Xcode warning when using deprecated setStatusBarHidden method

I found this on StackOverflow regarding the problem, but was not able to solve my problem.

Calling the appropriate setStatusBarHidden per iOS version

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
else 
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];

I set my OS deployment target to 3.0, yet I still recieve the warning 'setStatusBarHidden:animated: is deprecated'

I'd like to have no warnings if possible in the project, and not a hack that removes it. Is there a way I'm supposed to set up the project to remove this warning?

I've set the project base SDK to 4.0. And the target Base SDK to 4.0, deployment target SDK to 3.0.

I made these settings for 'All configurations'

Update: Apparently the warning only appears in the simulator, not when set for Device.

Upvotes: 3

Views: 7768

Answers (3)

anish
anish

Reputation: 51

you can perform it like this to overcome the warnings at once

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
(void) methodUsingDeprecatedStuff { //use deprecated stuff }

or

Just paste this line before using your deprecated stuffs every time to avoid warnings

#pragma GCC diagnostic warning "-Wdeprecated-declarations"

this will remove the warnings.

Hope it will help you.

Upvotes: 1

Daniel Brown
Daniel Brown

Reputation: 31

This might help, if you develop for older devices, not sure about the last but it looks nice:

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: animated:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

However, the problem came up after I switched Devices from iPhone to Universal and back to iPhone. Took me a while to realize that Deployment Target was changed to 4.3, so changing it back to 3.0 made the warning disappear.

Upvotes: 3

Steve Weet
Steve Weet

Reputation: 28392

A deprecation warning means that you are using something that will not be supported in the future. This particular syntax is listed as deprecated here. You get rid of the warning by not using the deprecated method. You should be using setStatusBarHidden:withAnimation: instead

If you wish to support this functionality on both 3.0 and 3.2+ then you will have to write conditional code based upon the target version. There is some useful information on pre-processor macros and functions to help you here.

Upvotes: 4

Related Questions