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?
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.
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.
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.
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.
Related
In iOS version of app, sample/template files are added to Xcode in a group and then become a directory of that name within the app bundle. Easy enough.
What is the Cocoa equivalent? When I try the same thing, Xcode (Swift 3) fails on build with a "Command /usr/bin/codesign failed with exit code 1". How does one add support files (or directory of files) to a Cocoa app?
In macOS, I guess you mean that, every App creates a Resources Folder inside the NSBundle. Just check with right click "Show Bundle Content".
If you add resources to Xcode, just by dragging the file anywhere in your project navigation, will be asked to copy that file if needed.
I usually create a group with Supporting File, but thats arbitrary, because it has nothing to do with the file structure inside the project folder on disk nor with the product package.
To create groups just right mouse and select group.
This copies the file inside the Xcode project Folder. And if you choose to add target, then the file will be included to that Resource folder.
You can ask for that File with:
let bundle = Bundle.main
let path = bundle.path(forResource: "Test", ofType: "txt")
Edit
if you have to code sign your resources, then ope the copy files menu in Build Phases, add with the plus button your resource and check code sign on copy. This should provide a proper signing for your resource.
Hope it helps!
Normally when you create a new WKInterfaceController you just select the WKInterfaceController class and Swift/Obj-C. But the next screen gives you 3 options for choosing the target; iOS app, WatchKit App and WatchKit Extension. It is defaulting to the iOS app for me so I am concerned that maybe I selected the wrong targets for my previous classes.
How do you know what target to select? Is it usually always the WatchKit Extension since that's what we're obviously putting our classes in? It seems obvious I know but I want to make sure because I often get confused with what targets to add binaries, classes and everything else to.
If I have made a mistake in choosing the target for a new WKInterfaceController.swift file where do I fix it? Would I fix it in Build Phases -> Compile Sources?
Apple says here when creating a WKUserNotificationInterfaceController to add it to the WatchKit Extension target. But does that apply to our own custom WKInterfaceController classes as well?
You'd add it to the WatchKit Extension.
Notification controller, glance controllers, complication controllers, and interface controllers all run in the extension.
An interface controller runs in your WatchKit extension and remotely manages the behavior associated with an interface controller in your Watch app’s storyboard file.
If you made a mistake and added it to the wrong group, you'd correct it in that same (Utilities File Inspector) pane, by simply unchecking the wrong target, then checking the proper target.
If I start adding a file by double clicking on the WatchKit Extension, then it defaults to choosing the WatchKit Extension for the location of the file. Do you perhaps choose New File from the top menu? It probably doesn't default then.
So yes, you should add WatchKit user interface classes like this to the WatchKit Extension.
As to 2), you can change file membership in the file properties on the right pane, using the File Inspector. You'll see a Target Membership check box there. This will change membership, but as I remember it will not move the file on disk, so just be aware of that if you do it this way.
I need to put a plugin (specifically a QuickLook plugin) in /Contents/Library/QuickLook in my app bundle.
This is easy to do in Finder by clicking Show Package Contents and so forth, but I would like Xcode to do this every time I build my app.
How would I accomplish this? (Xcode 4)
You could add a new Copy Files Build Task to your target, as described by MarkPowell in his answer to this question.
I added .png images to the Xcode project for conditional use like making screenshots of a view
However, since this is not needed for the Release version of the app, I would like to find a way to exclude them using some kind of settings for Target. I expect there can be a solution like using #if DEBUG macro for Debug compilation, which can work for lines of source code. But, in case of files included in project bundle, I am having trouble finding the answers.
In Xcode 3, there's a view above the editor that lists the files in the project. There's a checkbox on the right side of that view for each file, and you can uncheck the box to remove the file from the current target.
In Xcode 4, show the Project Navigator on the left side of the window, and show the File Inspector on the right side, in the Utilities area. When you select a file, you'll see a Target Membership area with a list of targets and checkboxes. If you want to exclude the file from a particular target, uncheck the box next to that target. Here's a picture:
This is a bit different from excluding files from only some builds of a single target. Still, I think it's the simplest mechanism to use for the situation that you describe. Simply duplicate your existing target so that you have a copy that you can use for making screenshots. Remove the extra files from your production target but leave them in the screenshot target, as described above.
A target's inputs are the same for all builds, so there's no checkbox that will do it for you.
All that really happens though is that image files like .png or whatever get added to the copy bundle resources phase. You can remove them from that phase and instead create a custom script build phase using a shell script.
It will default to printing out all the environment variables set by xcode, from there you should be able to write a script which only performs the copy when say ${BUILD_STYLE} is 'Debug'.
You probably want ${BUILD_STYLE}, ${CONTENTS_FOLDER_PATH} and ${INPUT_FILE_PATH} for starters.
I've got an Xcode project that creates a standard application that can be branded in multiple ways and contain some custom content. At the moment I have a Resource "Resources > Tour Packages" with the custom files under this. At the moment every time I want to brand the app a different way I have to delete the old files from this resource and then manually add the new versions via the XCode UI. I can't post and image but it is here - http://img.skitch.com/20100121-xub48r6e1p857c84hdrgg25dw6.jpg).
My Question: Is there a command line tool that performs the same operation?
You'd probably be better off just creating multiple targets in your Xcode project, and associating the resources for each branded version of the app with one target.
To do this, just right-click on your target and select Duplicate. You should then remove the custom resources from the Copy bundle resources build phase. You can then add a new set of resources to the Copy bundle resources build phase that are specific to the new target. You can then build any target you like by selecting it from the Active Target popup in the Xcode toolbar or by selecting it in the Project > Set Active Target menu.
This way, you can easily build different versions of your app without having complete duplicates of all your source, difference Xcode projects etc.
Yes, the xcodeproj ruby gem allows you to add resources. https://rubygems.org/gems/xcodeproj/versions/0.28.2