Search code examples
filebundlesandbox

getting file into app bundle (the library folder)


I have created an app and tested it on a simulator. It normally accesses a .plist file for some data, which ive stored in the appropriate place on my mac.

I want to access this file whilst testing my app on an iPhone (I have the file in my supporting files folder) but I haven't been able to find a way of doing this. How do i get my file in this directory so that my app can access it.

/var/mobile/Applications/......./Library/freq.plist

The answer must be so bleeding obvious seeing that ive not found anything on it on google!


Solution

  • It isn't quite clear from the question whether you want to a) access a .plist file that is only accessed by the app, or b) access it both with the app and also with your MAC without using the app.

    If you want a) just include it in the app's bundle and refer to it in your code by its name without giving its path. To include it in the bundle "Add" it to the files shown in the Project Navigator (the left panel in Xcode with the first tab at the top selected). To add it, first highlight (single click) one of the folder icons in the Project Navigator panel to indicate where you want the .plist file to appear, type command-option-A, find the file on the MAC with the window that opens, be sure "Copy items into destination group's folder (if needed)" is checked, then click "Add". It now appears in the left panel and you can access it programmatically by its unqualified name. If you forget to check "Copy items into destination group's folder (if needed)" you'll have hard-to-understand problems. To remove it from the bundle right click its icon in the Project Navigator panel then select "Delete". You'll be given an option whether to also trash the file.

    If you are asking b), that's more complicated, trouble-prone, and probably not a good thing to even attempt.