iOS How to use private API?

眉间皱痕 提交于 2019-12-30 04:49:12

问题


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

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.

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.

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.

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.


回答1:


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

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

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

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

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).



来源:https://stackoverflow.com/questions/11070089/ios-how-to-use-private-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!