iOS 如何使用私有 API? [英] iOS How to use private API?

查看:18
本文介绍了iOS 如何使用私有 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想将此应用提交到 AppStore.我已经尝试了很多次,但遇到了很多问题:(

I don't want to submit this app to AppStore. I've tried for many times but met so many problems :(

我使用 class-dump 来获取 UIKit.framework 的所有头文件.在class-dump生成的UIApplication.h中,看到了我要使用的方法----launchApplicationWithIdentifier.

I use class-dump to get all the header files of UIKit.framework. In the UIApplication.h generated by class-dump, I saw the method I want to use----launchApplicationWithIdentifier.

然后我将 UIApplication.h 放入我的项目中并导入它.编译,我得到了很多重新定义枚举器......"错误,因为在我之前使用的 UIKit.framework 中,还有另一个 UIApplication.h.但是这个文件没有launchApplicationWithIdentifier方法.

Then I put UIApplication.h in my project and import it. Compile, I got a lot of "Redefinition of enumerator...." error because in the UIKit.framework I use previous, there's another UIApplication.h. But this file doesn't have the method launchApplicationWithIdentifier.

如果我删除之前的 UIKit.framework 并导入 class-dump 生成的文件夹.然后它看起来像一个框架,但如果我展开它,它是空的.

If I delete the previous UIKit.framework and import the folder generated by class-dump. Then it appears like a framework but if I unfold it, it's empty.

然后我想让所有生成的头文件成为一个框架文件,替换之前的UIKit.framework.但我不知道怎么做.我们可以看到,在系统框架目录下,有一个与框架同名的文件,并且有一个已执行的shell脚本"图标.我怎样才能制作这个文件?

Then I want to make all generated header files a framework file ant replace the previous UIKit.framework. But I don't know how. As we can see, under the system framework directory, there's a file which has the same name as the framework and has a 'executed shell script' icon. How can I made this file?

我真的很困惑.有人可以帮我一把吗?谢谢.

I really got confused. Someone can give me a hand? Thank you.

推荐答案

只要在你想使用的类实现上面的类别接口中指定私有方法,像这样:

Just specify the private methods in a category interface above the class implementation where you want to use it, like this:

@interface UIApplication (Private)

- (BOOL)launchApplicationWithIdentifier:(id)identifier suspended:(BOOL)suspended;

@end

不要导入整个类转储文件并与原始 UIKit 框架链接.

Don't import the whole class-dump file and link with the original UIKit framework.

使用私有 API 时必须非常小心.这些方法可以在未来的 iOS 版本中更改或删除!

You must be very careful when using private API. These methods can change or be removed in future iOS versions!

在运行时用 respondsToSelector: 检查方法是否真的存在,并为它不存在的情况做好准备.

Check if the method really exists with respondsToSelector: at runtime and be prepared for the case that it does not exist.

我在自己的应用程序中使用了一个秘密的 MapKit 功能,并且我知道私有方法仅存在于 iOS 5 中.所以我的应用程序仍然适用于所有 iOS 版本,但此功能仅在 iOS 5 中可用(Apple 删除或更改了它在 iOS 6 beta 1) 中.

I used a secret MapKit feature in my own application and I knew that the private methods only exist in iOS 5. So my app still works in all iOS versions but this feature is only available in iOS 5 (Apple removed or changed it in iOS 6 beta 1).

这篇关于iOS 如何使用私有 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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