Andrew Chang
Andrew Chang

Reputation: 1319

How to build and embed another application inside my target in Xcode?

I have an application in my project (named App_Main). And I want to package another tiny application (let's call it App_Tiny) inside the package of App_Main.

Then, as I know App_tiny's path, I can execute App_Tiny programmatically in App_Main's run-time when I need that.

How can I achieve this? How to specify and build another executable target, AND, most importantly, automatically put App_Tiny inside the package directory of App_Main?

Upvotes: 8

Views: 3154

Answers (1)

Warren Burton
Warren Burton

Reputation: 17382

For adding a new target it's as easy as hitting the "New Target" button in the left hand pane of your project explorer. Xcode will allow you to choose the target type (Application) when you add it.

new target button

Next you need to add FooBarTiny as a build dependancy for your main app (FooBar). Edit the Scheme for your Main Target and add the sub target as an explicit dependancy.

enter image description here

Now when you build FooBar; FooBarTiny will be built if it needs to be.

Next you add FooBarTiny into the "Copy Bundle Resources" phase. Hit the add button and scroll down the tree and you can find FooBarTiny in the Products folder.

enter image description here

To launch FooBarTiny from within your app you can use NSWorkspace.

- (NSRunningApplication *)launchApplicationAtURL:(NSURL *)url options:(NSWorkspaceLaunchOptions)options configuration:(NSDictionary *)configuration error:(NSError **)error would probably be a good start point. Check the API docs for other variants.

EXTRA FOR THE APP STORE

It's not enough to sign your main app. Any Applescripts and sub-apps (FooBarTiny) will have to be signed as well or your app will fail validation. This answer isn't about that but theres a good blog on the issue here.

Upvotes: 6

Related Questions