Search code examples
xcodecocoaframeworksxpc

Sharing a single copy of a framework with multiple bundles


I have a framework that is being used in my application, plus a few XPC services contained inside the application bundle. How can I link all the bundles to the single copy of the framework contained inside the application's Frameworks folder (vs copying the framework to every bundle)? All of the services and the application are sandboxed, so I'm not sure if the XPC services would be able to access the Framework in the main app bundle as it would be outside of the sandbox.


Solution

  • This is possible using install_name_tool. Example:

    install_name_tool -change @executable_path/../Frameworks/MyFramework.framework/Versions/A/MyFramework @executable_path/../../../../Frameworks/MyFramework.framework/Versions/A/MyFramework "$BUILT_PRODUCTS_DIR/MyApp.app/Contents/XPCServices/com.me.MyApp.SomeXPC.xpc/Contents/MacOS/com.me.MyApp.SomeXPC"
    

    More information here.