Xcode 8中的UIScreen mainScreen [英] UIScreen mainScreen in Xcode 8

查看:72
本文介绍了Xcode 8中的UIScreen mainScreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Xcode 8中遇到了iOS SDK的问题.

We have a problem with iOS SDK in Xcode 8.

我们在项目中使用方法[UIScreen mainScreen]. iOS 2.0中提供了此方法.

We use method [UIScreen mainScreen] in our project. This method is available from iOS 2.0.

但是,当我们在Xcode 8中构建产品并将其提交以供审核时,应用被拒绝了.惊喜:在新的SDK( Xcode 8 GM )中,此方法标记为"可用于iOS 10.0 ".换句话说,现在iOS 9将[UIScreen mainScreen]标识为"非公开API ".

But when we built product in Xcode 8 and submited it for review, app was rejected. Surprise: in the new SDK (Xcode 8 GM) this method marked as "available from iOS 10.0". In other words - now iOS 9 identifies [UIScreen mainScreen] as "non-public API".

也许这是苹果的错误.

我们的问题:
1)我们要继续使用此方法.
2)我们要支持iOS 8和iOS9.
3)我们要使用Xcode8.
有可能吗?

Our question:
1) We want to continue using this method.
2) We want to support iOS 8 and iOS 9.
3) We want to use Xcode 8.
Is that possible?

推荐答案

类属性是Xcode 8中提供的Objective-C功能,看起来mainScreen已在API

Class properties are an Objective-C feature available in Xcode 8 and it looks like mainScreen has been refactored in the API to be one. The error of mainScreen being non-public seems like a misleading error/bug on Apple's end, but if you use the class property accessor the error might go away.

好消息是,由于它是语言功能,而不是特定于iOS版本的,因此您应该能够采用类属性语法,即UIScreen.mainScreen,并继续支持iOS 8-9.

The good news is, since it is a language feature, not iOS version specific, you should be able to adopt class property syntax, i.e. UIScreen.mainScreen, and continue to support iOS 8-9.

p.s. mainBundle现在也是一个类属性,因此,如果使用它,则可能会触发相同的错误.

p.s. mainBundle is also now a class property, so if you use that, it's possible it would trigger the same error.

这篇关于Xcode 8中的UIScreen mainScreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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