根据 iOS 版本调用适当的 setStatusBarHidden
今天我的应用程序获得了批准,但我收到用户发来的电子邮件说它崩溃了。我发现这
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
就是问题所在,因为用户的固件为 3.1.x,所以该 API 无法正常工作并且应用程序崩溃。
所以我将其替换为
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=3.2)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
我的问题...
我所做的是最好的解决方案吗?
当我设置 Traget OS 固件 3.0 时,为什么 XCODE 没有警告我 SetStatusBarHidden withAnimation 不在 3.0 中?
我是否必须检查每个 API 以查看它是否适用于我的目标操作系统?
谢谢
Today my app approved, but I got emails from users says it crash. I figured out that
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
Is the problem, Because users have firmware 3.1.x this API is not working and app crash.
So I have replace it with
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?
Why XCODE did not warn me that SetStatusBarHidden withAnimation is not in 3.0 while I set my Traget OS firmware 3.0?
Do I have to check on every API to see if it is working with my Target OS?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,如果您使用模拟器使用 4.0 SDK 进行编译,上述解决方案会给您一个警告,默认情况下该警告被视为错误:
因此您可以在构建设置中将“将警告视为错误”设置为 false,或者您可以使用宏有条件地包含正确的代码。我的基本 SDK 设置为 Device 4.0,我的目标操作系统是 3.1,并且正在使用此宏:
请注意,setStatusBarHidden:withAnimation 在 3.2 中可用。
Unfortunately, if you are compiling with the 4.0 SDK using the simulator, the above solutions will give you a warning, which by default is treated as an error:
So you can either set 'Treat warnings as errors' to false in the build settings, or you can use macros to conditionally include the correct code. I have my base SDK set to Device 4.0, my target os is 3.1, and am using this macro:
Note that setStatusBarHidden:withAnimation came available in 3.2.
除了将您的应用程序限制为 >=3.2 之外,这可能是最好的选择。不管怎样,你的 xcode 应该给你一个警告,告诉你不支持 SetStatusBarHidden withAnimation 消息(“可能不会响应”)。
That's probably the best thing to do, other than limiting your application to >=3.2. anyways, you xcode should give you a warning that the SetStatusBarHidden withAnimation message is not supported ("may not respond to").
我建议您使用以下代码片段,而不是检查操作系统的版本,而是检查选择器当前是否可用。
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.
仅使用
而不是
它的工作原理没有任何警告
Use only
instead of
It works with no warning