Apple 和私有 API
既然众所周知,App Store 提交正在接受私有 API 的使用测试,我需要问一个问题……私有 API 到底是什么,以便我可以避免使用它们?
Now that it's public knowledge that App Store submissions are being tested for use of private APIs, I need to ask the question... what exactly is a private API so that I may avoid them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
私有 API 是未记录在 SDK 中的 API。例如,框架类可能声明一个不适合外部开发人员使用的方法。不保证私有 API 的行为。您甚至无法确定该方法是否会出现在平台的未来更新中。它的声明可能在公开分发的 SDK 头文件中不可用。如果您坚持 SDK 文档中公开定义的内容,那就没问题。
A private API is an API that is not documented in the SDK. For instance, a framework class might declare a method that is not intended to be used by outside developers. The behavior of a private API is not guaranteed. You can't even be sure that the method will be there in the future updates of the platform. Its declaration is probably not available in publicly distributed SDK header files. If you stick to things publicly defined in the SDK documentation, you'll be OK.
您会发现很难意外地使用私有 API。它们没有记录在 SDK 文档中,也没有出现在 XCode 的代码完成建议中。
最近这件事成为新闻的原因是,多个应用程序使用的框架的创建者使用了私有 API,因此当包含他的框架的开发人员更新他们的应用程序时,他们被拒绝了(即使那些开发人员没有使用私有 API,他们添加到应用程序中的框架确实如此)。
这大概是您可能意外使用私有 API 的唯一方法。
You will find it difficult to use a private API by accident. They are not documented within the SDK docs, and they don't show up in XCode's code completion suggestions.
The reason this has become news recently is the creator of a framework used by several apps used a private API, so when developers who included his framework updated their apps, they were rejected (even though THOSE developers didn't use a private API, the framework they added to their application did).
That's about the only way you could possibly use a private API accidentally.
不仅仅是私有 API 会导致您的应用程序被拒绝。使用公共 API 的未记录成员可能会导致您的应用程序被拒绝。例如,two20 库(已修复)访问了类别中的 _phase 和 UITouch 的其他成员。
他们还可以通过 PerformSelector 检测对 private 成员的调用,因为以下也标记了拒绝:
更令人不安的是,如果您使应用程序在 3.1 和 3.0 下工作,并且在 3.0 中运行时,您不使用任何3.1 你的申请仍然可能被拒绝。一个示例可能是
UIImagePickerController
的cameraOverlayView
(请参阅此处)。这有点令人费解。It's not just private APIs that can cause your application to get rejected. Using undocumented members of a public API can cause your application to get rejected. For example, the three20 library (since fixed) accessed _phase and other members of UITouch within a category.
They can also detect calls to private members via performSelector, as the following also flagged a rejection:
More disturbing, if you make your application work under 3.1 and 3.0 and at runtime in 3.0 you don't use any of 3.1 stuff your application can still get rejected. An example might be the
cameraOverlayView
ofUIImagePickerController
(see here). This is kind of puzzling.通常是由于 SDK 标头中没有它们。苹果的约定之一是以下划线开头的 ObjC 方法名称。
Generally by their absence from SDK headers. One of apple's conventions is to lead ObjC method names with underscores.
App Scanner 是您在提交应用程序之前使用的一个很棒的工具。 私有 API 使用情况,并向您显示匹配的方法签名以及这些方法所在的类。
它会扫描您的 .app 文件以查找 http://www.chimpstudios.com/appscanner/
A great tool to use before you submit your app is App Scanner. It scans your .app file for private API usage and shows you what method signatures match up and what classes those methods are in.
link --> http://www.chimpstudios.com/appscanner/
我的应用程序因使用私有API而被苹果拒绝。这是代码,
My app was rejected by apple because of using private API.Here is code,
被所谓的“使用私有API”拒绝并不难。尝试使用以下内容作为核心数据属性,它将被拒绝:
如何扫描API。
It is not difficult to get rejected by so called "using private API". Try to use the following as Core Data attribute and it would be rejected:
It shows how the robot scans the API.