Today I had to use a private API while spiking a feature for an iPhone app I'm working on and I ran into a couple of gotchas along the way. There doesn't seem to be a simple step-by-step guide for using private iPhone APIs in XCode, so here's goes:
- First off, you're going to need the header files for the private frameworks. To dump them, use the Framework Dump Kit from Erica Sadun's site. Download the DumpFrameworks Perl script anywhere and put the class-dump binary somewhere on your path (I put it in /usr/local/bin/)
- Run DumpFrameworks (navigate to the folder you downloaded it to in Terminal and type
./DumpFrameworks). This will create the headers in ~/Headers. - In your XCode project, right-click the Frameworks folder in the Groups & Files panel and select Add → Existing Frameworks. Navigate to the header file(s) you want to add and select them. You should see the headers added to your project.
- Go to Project → Edit Project Settings, click on the Build tab, and scroll down to the Linking section. For the Other Linker Flags property, enter
-force_flat_namespaceand-undefined suppress(thank you, Ken Ferry). If you forget this, you will get a linker error telling you that the symbols for the private classes you're using could not be found. - Open up the header files you imported into your project and remove the superfluous import statements that the header dumper put there. Usually this is just an unnecessary
#import "NSObject.h"but there may be others also. If you get errors, look for the SomeHeader.h: No such file or directory messages and remove the import statements corresponding to those errors from the private header files. - Finally, import the private header files, use the classes in your application, build and run!
Of course, whether or not you should use the iPhone private API is another matter (undocumented calls may break at any time, Apple may reject your app, etc.) If you do want to play around with them, however, I hope the above instructions help you to get started without too much pain.
The Private iPhone APIs in XCode for Dummies article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
What kind of API calls did you need then? Might be handy. Would be nice if they had some Private API call to add calendar events…
Nothing too sexy; APIs that I’m assuming Apple will make public with the next release since they’re necessary to use some of the other public APIs.
Hi,
Is this is right that Apple can application if you use private frameworks…
and is there any application which uses them..
i want to use Celestail framework for Recording voice in one of my application along with playing.
Please help me….
there is any way to record and play sound simultaneous. I need to save it in file…
[...] Timberline: File Index Aral Balkan – Private iPhone APIs in XCode for Dummies [...]
Does this work with XCode 3.1.3 and the 3.0 APIs?
Hi Aral,
I know this is a late reply to your post but I’ll hope you’ll read it.
First, thanks for an excellent article.
I’ve followed your little tutorial but I get an error that I can’t solve for the moment. After importing the header “PLCameraController.h” to my class I get the following build error:
/Users/usr/Playground/Collage/../../Headers/PrivateFrameworks/PhotoLibrary/PLCameraController.h:21: error: cannot find protocol declaration for ‘PLCameraControllerDelegate’
Do you have any idea on what to do here?
Thanks,
Andreas
Hey Andreas,
Have you tried doing a search for the Delegate protocol that’s missing and importing the header file that you find it in? I haven’t been playing with private frameworks since this post so not sure what advice I can give beyond that. (Apart from that, maybe trying to create an empty protocol with that name and see if it balks?)
Hey Andreas
Did you solved this?
If you did, Could you post it here? I will appreciate it very much.
Thanks again
Hi Aral,
I tried using the dumpkit for SDK 3.1.2 but it seems to break:
class-dump: Input file (/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/ApplicationServices.framework) doesn’t contain an executable.
Any idea how to fix this? Hope so i’m eager for the sdk’s headers ;)
Hey EeKay, I’m sorry but I haven’t tried it in 3.1.2. If past performance is any indication, however, I’m sure the Erika will release the headers soon, if she hasn’t done so already :)
[...] to Aral Balkan today I finally made some progress. Can’t explain why due to NDA reasons but the app is [...]
Hello,
I got the different frameworks but there isn’t MediaPlayer.framework, how can I use private classes of this framework?
Thanks
[...] 参考Aral Balkan的文章。 相关文章iPhone开发技巧之环境篇(7)— 区分不同版本的iPhone – [...]
Hi Aral,
I followed all the steps mentioned in this blog to extract the private api’s and when I tried to run the application in the device, I am getting the following error in the console :
dyld: Symbol not found: _OBJC_CLASS_$_ICSCalendar
Referenced from: /var/mobile/Applications/F8E70001-ED03-4207-BEBF-44A4EDDB04A3/privateApiAccess.app/privateApiAccess
Expected in: flat namespace
I also added the linker flags as mentioned . I am trying to access the calendar in iPhone using the “ICSCalendar.h”. Any help in fixing this issue will be much helpful.
Best Regards,
Mohammed Sadiq.
Hi Aral,
Is there any specific private api’s available o access the sms, calendar, notes, music files, videos, pictures , documents etc .
Dear Mr Balkan,
Reading the others comment makes me feel like a real n00B. I am not even able to run the perl script from erica saduns site. I actually downloaded class-dump from a site called codethecode. Will that be a problem?
By the way, great site and blog
Hi Aral Balkan,
I have tried using your approach, but I got “no such file or directory” error, it is actually complained my added header file (let call it A.h), not the file that A.h refer to (let call it B.h).
I dont really understand why it complaint about A.h when I added A.h to the project.
Do we need to add the binary of the framework as well ?
Please help me with this, thank you.
Hi,
I need to dump out the headers from iPhone SDK 4.0. But am getting the warning Objective C runtime information not found. But when I tried with 3.0 I was able to get the headers. Any idea?
Regards,
Syam
we feel so glad to have you visit our website, we here mainly introsuce our leading product<a
Hi,
I tried the steps you mentioned, but get the error for maximum frameworks as “Warning: This file does not contain any Objective-C runtime information.”
I tried the steps on all sdk’s ranging from 3.0 to 4.3 (Changed the file path in DumpFrameworks.pl to the relative version), but none works. Please suggest.