Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

macos

build

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?

like image 648
Andrew Chang Avatar asked Dec 24 '13 09:12

Andrew Chang


People also ask

How do I add files to target in Xcode?

I include them in the project by right-clicking on the project folder in the project view in Xcode, and selecting "Add Files to ...". I then navigate to the folder containing the source files, click on the folder and select "Add." With the options "Create folder references" and "Add to target [target name]".

How do I build and run an app in Xcode?

To build and run your code, choose Product > Run, or click the Run button in your project's toolbar. Xcode analyzes your scheme's targets and builds them in the proper sequence. After a successful build, Xcode launches the associated app.


1 Answers

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.

like image 81
Warren Burton Avatar answered Sep 23 '22 17:09

Warren Burton