每个iOS版本调用适当的setStatusBarHidden [英] Calling the appropriate setStatusBarHidden per iOS version

查看:901
本文介绍了每个iOS版本调用适当的setStatusBarHidden的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我的应用程序获得批准,但我收到用户的电子邮件说它崩溃了。我想出了

Today my app approved, but I got emails from users says it crash. I figured out that

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];

问题是,因为用户有固件3.1.x,这个API无效,应用程序崩溃。

Is the problem, Because users have firmware 3.1.x this API is not working and app crash.

所以我用

    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=3.2)
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
    else 
        [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

我的问题......

My questions...

是我做了什么最好的解决方案?

Is what I did the best solution?

为什么XCODE没有警告我在设置Traget OS固件3.0时SetStatusBarHidden withAnimation不在3.0中?

Why XCODE did not warn me that SetStatusBarHidden withAnimation is not in 3.0 while I set my Traget OS firmware 3.0?

我是否必须检查每个API以查看它是否与我的目标操作系统一起使用?

Do I have to check on every API to see if it is working with my Target OS?

谢谢

推荐答案

我建议您使用以下代码snipplet而不是检查操作系统的版本,而是检查选择器当前是否可用。

I'd recommend you to use the following snipplet of code instead of checking against the version of the os, rather check if a selector is currently available.

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

这篇关于每个iOS版本调用适当的setStatusBarHidden的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆