deploying resource files from xcode - xcode

How does one copy resource files (config/data/image) files to an applictions home directory on the iPhone.
A related question Loading Data Files on iPhone?, received an answer "just add them to your project; Xcode will copy them to the .app bundle when it builds your application".
How does one do this? (If this is a simple question, a manual reference/page# is fine)
I want to be able to copy a file onto the iPhone simulator and open it at runtime. I have tried to do this by adding 'copy file' targets, although I havent been able to find the files at runtime.
I know using property list, or sql lite database is prefered over file io, but I would still like to understand how to achieve this.

In my app, I have a sql lite DB which I just dropped in the root of my project folder and added to the resources folder of my project, and it winds up in the bundle, accessible by the app.
http://img68.imageshack.us/img68/3047/xcoderesourceslw5.png
I assume this will work for any file. I didn't have to write any special targets or operations.
In your app, this file then shows up as follows:
NSString *dbFilePath = [[NSBundle mainBundle]
pathForResource:#"dictionary"
ofType:#"db"];

I just found this site, Bundle Programming Guide it explains, how to access resources set in your project at runtime. I assume its just as easy to use single files.

Related

How to associate file during folder copy on Mac OS X

I involved with the development of an application that is intended to deploy on multiple desktop system including the Macintosh.
Our team decided we would like to a drag and drop installation for the Macintosh. However, the application is intended to ship with other content besides the application itself such as example files.
Originally these files were placed in the application bundle, however this was discovered to be problematic as the cross platform libraries used for the user interface will not allow someone to access the contents in the bundle. Also force users to have to dive into a bundle to find content does not offer a great user experience.
To that end, we decided to pull these examples file and what not out of the bundle and place them in a separated folder that lived along side the application bundle. To make sure everything including the examples and the application were copied together during the drag and drop installation, a new top level folder was created that contained everything to be copied.
The problem that now exists is that whereby when originally just the application bundle was copied over to the system, the copying of this top level folder does not cause file associations for the application to occur automatically.
What can be done to associate an application with certain files when someone installs by dragging a folder contain the application bundle?
I suggest you to deliver it separately in one dmg. So your dmg structure will look like next:
MyApp -> Applications
MyApp Examples -> Application Support
Simple, user-friendly, no problems with association.
Actually it looks like the file association is working after all. Someone reported a defect against the installation not making the associations. However, I just tested the installation on a clean system and copying over the folder does seem to make the associations.

ClickOnce Application looking in wrong directory

I have a program I made with an SQL database. Everything works fine in VS 2010. But then I publish it and it throws up an error saying it cannot find my database. I used |DataDirectory| when I wrote the string for it so I searched for my database file.
I found a folder with my database an the application file in it. I double clicked it and what do ya know, works fine. My only problems is all the shortcuts that the install makes don't work, they point to an empty folder. Is there a way to make them linked to this good folder that the installer makes?
I notice its looking for my database under a filepath under the folder name "data". In the AppData/Local on my comp where the application is installed to there are 2 folders. One leads to my app, the other one leads to nothing, and is labled "data." It seems my program keeps looking in there, but like I said, if I follow the other path and run the .exe right from that folder it runs fine.
Make sure your database is part of your project, and that the build type is "content", and "copy to output" is set to "copy always". In the Application Files dialog, make sure the database shows up, and is marked Data (which it sounds like you have). Is the database included in the deployment when you publish (check the output)? IF not, is it included in the files output when you build the project?

Resource not being bundled into app

I have shaders named basic_shader.vsh and basic_shader.fsh. I added both of these two files to the Copy Bundle Resources build phase. But they are not being copied into the bundle app. And they don't appear in the Log Navigator. Xcode builder effectively ignores them.
They are located into a directory outside the source directory. I don't know if that is relevant. The funny thing is that a png image also located outside the source directory is being copied inside the bundle. My app is a Mac OS X app using Cocoa.
I solved by adding into the Copy Files build phase (setting the destination to Resources) instead of the Copy Bundle Resources build phase... I don't know why it solves the problem as I don't really understand the problem, actually...
Thanks anyway...
For some reason .metal files are not regarded as resources. If you just change the extension to anything else they're copied in the bundle.
Make sure your shaders are copied into your resources

Creating a Cocoa Framework

I've created a working Cocoa framework which I wish to redistribute. The problem is however, it won't run outside of Xcode. I've read something about #executable_path/../Frameworks, which I did not include, because I don't know where to put it :/
Therefore I run my app in Xcode using the DYLD_FRAMEWORK_PATH variable which works fine, but only in Xcode - if I try to run it on its own it crashes straight away and says IMAGE NOT FOUND.
I'm sure #executable_path/../Frameworks is what's missing, but I don't know where to put it.
Could anyone help me out please? :)
Thanks
Here is how I usually manage things:
In the framework's Xcode project, set the Installation Directory to #rpath
Add the framework to your application's Xcode project. Add a Copy Files build phase, select Frameworks in the Destination popup, and ensure your framework is added so it will be copied to your application's Frameworks directory when it is built.
Finally, in your project's settings, add #loader_path/../Frameworks to Runpath Search Paths.
Are you actually copying the framework into your applications bundle? Look for the folder called MacOS which is what contains the binary. There should be another folder at the same level called Frameworks and it should have the framework inside it.
If it's not there you need to create a copy files build phase for the application that copies the framework into the Frameworks folder.

how do I package support files in a cocoa app

I'm building an application where I want to provide the user with a few dozen templates that will internally take the form of property lists. I would also want to group them in categories, which would conveniently be achieved using folders.
While I have contemplated shipping these files as simple resources in my application, I don't like the idea of this single location containing dozens and dozens of files, and besides it doesn't seem to be possible to group them in folders.
I can see that many applications have installed such resources in their application support directory (~/Library/Application Support//...), but I can't seem to find any documentation resource on how to achieve this.
I don't like the idea of this single location containing dozens and dozens of files, and besides it doesn't seem to be possible to group them in folders.
It is. Put them in folders in your project directory, then add the top-level folder(s) to your project. Make sure you add it/them as folder reference(s) and not group(s) (see? that sheet does have a purpose!).
Then, add the folder reference(s) to your Copy Bundle Resources or Copy Files phase.
One word of warning: When you change one of the files in the folder, you may need to “touch” the folder to get Xcode to re-copy it. You can do this in Xcode or from the terminal.
You can group items in sub-folders of your app bundle's Resources directory. Unless you want users to edit these plists, keeping them in your app bundle allows users to drag-n-drop install your app, rather than having to use an installer package (a big win).
You can group them into folders in your application bundle by adding a "New Copy Files Build Phase" to your project as described in this forum post:
http://forums.macrumors.com/showthread.php?t=458594

Resources