Friday, May 08, 2009 Embedding private framework in your iPhone app
Been trying to embed the JSON framework in a client’s project.
Apple has a Framework Programming Guide where you can find a chapter which covers this topic – Embedding a Private Framework in Your Application Bundle.
So I follow the procedures there which I would summarize into the following:
- Add the framework to your project
- Add a new Copy Files Build Phase to the application target. (This phase will be used to install the framework in the application bundle.)
- In the General tab of the inspector window, set the destination for the build phase to “Frameworks”.
Well… it doesn’t work at all… Guess the instruction is specific to Mac OS X instead of iPhone OS.
I got the following runtime error:
dyld: Library not loaded: @loader_path/../Frameworks/JSON.framework/Versions/A/JSON Referenced from: /Users/bill/Library/Application Support/iPhone Simulator/User/Applications/9A0DCEEB-BD46-45E0-AA7E-8C0409256267/CocoaZendesk.app/CocoaZendesk Reason: image not found
Google around for solution…
The discussion in objectiveflickr forum showed some hint. We should load the framework from @loader_path/Frameworks instead of @loader_path/../Frameworks.
To do so… add a “New Run Script Build Phase” and put the following in the inspector window:
/usr/bin/install_name_tool -change \ “@loader_path/../Frameworks/JSON.framework/Versions/A/JSON” \ “@loader_path/Frameworks/JSON.framework/Versions/A/JSON” \ “$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH”
It works!!
Finger - Top Paid Productivity App in Hong Kong! WWDC 09 Summary