xcode 在 iOS 9 中已弃用,兼容性如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32620204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:49:28  来源:igfitidea点击:

deprecated in iOS 9, compatibility?

iosxcodecompatibilitydeprecated

提问by Vjardel

I've upgraded my Xcode project with Xcode 7. I'm using Objective-C. When I'm targeting iOS 9.0in deployment target, I've 36 warnings :

我已经使用 Xcode 7 升级了我的 Xcode 项目。我正在使用Objective-C. 当我瞄准iOS 9.0部署目标时,我有 36 条警告:

  1. UIAlertViewis deprecated, use UIAlertController.
  2. ABAddressBookRefis deprecated, use CNContactStore...
  3. setStatusBarStyle:animatedis deprecated, use [UIViewController preferredStatusBarStyle]
  1. UIAlertView已弃用,请使用UIAlertController.
  2. ABAddressBookRef已弃用,请使用CNContactStore...
  3. setStatusBarStyle:animated已弃用,请使用 [UIViewController preferredStatusBarStyle]

and some other... Well, I would like to keep compatibility with iOS 9and at least iOS 8.

和其他一些......好吧,我想保持与iOS 9和 至少的兼容性iOS 8

Do I have to disregard these warnings for keeping compatibility with different OS ?

我是否必须忽略这些警告以保持与不同操作系统的兼容性?

If I use UIAlertControlleriOS 8, is it working ?

如果我使用UIAlertControlleriOS 8,它可以工作吗?

What the best thing I've to do ? Using deprecated or replace with new code ?

我必须做的最好的事情是什么?使用已弃用的代码还是替换为新代码?

回答by SomeGuy

If you are no longer targeting the older versions of iOS then its recommended to update deprecated code. You don't absolutely have to though, deprecated methods are still officially supported in Apple's SDKs, but one day Apple may remove those methods.

如果您不再针对旧版本的 iOS,那么建议您更新已弃用的代码。不过,您并非绝对必须这样做,Apple 的 SDK 中仍正式支持已弃用的方法,但总有一天 Apple 可能会删除这些方法。

Here's what Apple says about deprecation:

以下是 Apple 关于弃用的说明:

From time to time, Apple adds deprecation macros to APIs to indicate that those APIs should no longer be used in active development. When a deprecation occurs, it is not an immediate end-of-life to the specified API. Instead, it is the beginning of a grace period for transitioning off that API and onto newer and more modern replacements. Deprecated APIs typically remain present and usable in the system for a reasonable amount of time past the release in which they were deprecated. However, active development on them ceases and the APIs receive only minor changes—to accommodate security patches or to fix other critical bugs. Deprecated APIs may be removed entirely from a future version of the operating system.

As a developer, it is important that you avoid using deprecated APIs in your code as soon as possible. At a minimum, new code you write should never use deprecated APIs. And if you have existing code that uses deprecated APIs, update that code as soon as possible.Fortunately, the compiler generates warnings whenever it spots the use of a deprecated API in your code, and you can use those warnings to track down and remove all references to those APIs.

有时,Apple 会向 API 中添加弃用宏,以指示不应再在主动开发中使用这些 API。当发生弃用时,指定的 API 不会立即终止生命周期。相反,它是从该 API 过渡到更新和更现代的替代品的宽限期的开始。已弃用的 API 通常会在系统中保留并在其被弃用的版本之后的合理时间内可用。然而,对它们的积极开发停止了,API 只会收到很小的更改——以适应安全补丁或修复其他关键错误。不推荐使用的 API 可能会从操作系统的未来版本中完全删除。

作为开发人员,尽快避免在代码中使用已弃用的 API 很重要。至少,您编写的新代码不应使用已弃用的 API。如果您有使用已弃用 API 的现有代码,请尽快更新该代码。幸运的是,只要编译器发现您的代码中使用了已弃用的 API,就会生成警告,您可以使用这些警告来跟踪和删除对这些 API 的所有引用。

https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html

https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html

回答by rickster

"Deprecated" means at least one of the following:

“弃用”是指以下至少一项:

  • This API isn't gone yet, but it might be in the future, or on future platforms/technologies. For example, all API deprecated before iOS 8 is unavailable in Swift.
  • There's a better alternative to this API, and the old one might not keep doing everything you need as the platform changes. For example, AssetsLibrary is still around even though it's deprecated, but it doesn't provide access to iCloud Photos or Live Photos — for those you need its replacement the Photos framework.
  • 这个 API 还没有消失,但它可能会在未来出现,或者在未来的平台/技术上。例如,iOS 8 之前弃用的所有 API 在 Swift 中都不可用。
  • 这个 API 有一个更好的替代方案,随着平台的变化,旧的 API 可能无法满足您的所有需求。例如,尽管 AssetsLibrary 已被弃用,但它仍然存在,但它不提供对 iCloud 照片或实时照片的访问——对于那些需要替换照片框架的人。

Those are things to consider when targeting an OS version where the API are deprecated.

这些是针对不推荐使用 API 的操作系统版本时需要考虑的事项。

However, deprecation warnings are based on your project's minimum deployment target.If you tell Xcode that you want to build for iOS 7 and newer, you won't see warnings for APIs that are deprecated as of iOS 8 or iOS 9.

但是,弃用警告基于项目的最低部署目标。如果您告诉 Xcode 您要为 iOS 7 及更新版本构建,您将不会看到有关自 iOS 8 或 iOS 9 起已弃用的 API 的警告。

If you want to deploy back to an older minimum OS target, but use features from a newer OS, you need to put availability checks in your code that uses the newer features. See Apple's docson compatibility/availability and weak linking in general, and/or Checking API Availabilityfor Swift.

如果您想部署回较旧的最低操作系统目标,但使用来自较新操作系统的功能,则需要在使用较新功能的代码中进行可用性检查。请参阅Apple关于兼容性/可用性和一般弱链接的文档,和/或检查Swift 的API 可用性