Deploying Test Resources in the iPhone Simulator - iphone

I am working on an iPhone Application that stores images in the Applications 'Document' folder.
I am currently doing the majority of my testing using the iPhone Simulator. In order to aid development I want to have some test images pre-loaded into the Document folder of the application that my application can access and display.
I have discovered that when running the application in the iPhone simulator you can access the applications file system via
/Users//Library/Application Support/iPhone Simulator/User
The application is then represented by a UID and within that is the Document folder. Placing the images in this folder and they adding their path to my applications database allows me display test data.
The problem is that each time I build and redeploy the application the old application folder is deleted and a new one is created, this means I have to copy the images to the new application folder and update the database.
Is there a way to automatically add test resources to an application when building and deploying? Should I be putting the test data in the bundle instead, and if so is there a way to not include the test data when building the actual release?
Many thanks in advance

Xcode should be smart enough to migrate anything from your 'old' UUID-based folder hierarchy to the 'new' one each time you build. Are you not seeing this move automatically?
Note: you should definitely be using dynamically generated paths here, not hard-coded. Use [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; or [#"~/Documents" stringByExpandingTildeInPath] to get the proper (current) path to your documents folder.

Related

In Xcode 4.1 Database file is not displaying in build file

Using xcode 4.1 I am developing an application which is having database integration. I am able to do all functions on firefox Sqlite Manager plugin. When I add data to firefox, the data is being added properly by query. But I am not able to find the database file in the build folder of my application.
How can I get this file from within the application and from where ?
I have to check that the data inserted from the application is properly inserted or not because at the time of selecting & displaying the data, the application crashes.
Thanks in advance for guiding me & solving this problem.
Run application in iphone simolator and then insert data and the see the sqlite file at the path
home>Library>Application Support>Iphone Simulator>simulator type(like 5.0)>Applications
this path have many folders. folders have application data of all installed applications in simulator. search for your application and the open
Documents folder
here you have your sqlite file which store all your inserted data
Sometimes folders are hidden. so please check for hidden files and folders
Hope this will help.

iphone - how do I create a bundle and put files on it at run time

My app generates 3 files every time the user saves a project. I would like to be able to build a bundle at run time, and save all files to that bundle and save it to the app's directory. So if the user wants to move the project to the desktop its just the matter of dragging one bundle (= a directory that looks like a file, like the Mac OS X apps and Pages files)...
I googled around and found nothing.
How do I do that at run time?
thanks.
Bundles are really just folder hierarchies conforming to a specific structure – see the Bundle Programming Guide. You can use NSFileManager to create the folders in question, NSPropertyListSerialization to create the Info.plist, etc.

How do i test my app data persistence during development?

My question is related to the following three questions.
iPhone What happens to previous data when app is upgraded to new version
How the application upgrade works in iPhone
Preventing erasure of user data while upgrading iOS application via iTunes
Here are my 2 questions.
Am I supposed to create a "Documents" directory manually on filesystem or create just a "group" in xcode, so that when app is upgraded, data stay persistant?
How I can test the app persistance during the app development on simulator or on IPhone?
Thanks.
Neither. The Documents directory is created for you when your app is installed. You can get the path to it using:
NSString *docuDir = nil;
NSArray *list = NSSearchPathForDirectoriesInDomains(
NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
if ([list count]) docuDir = [list objectAtIndex:0U];
As #Ben said, the directory is only deleted when you explicitly uninstall the app (delete it from within Springboard). When you build and run, Xcode effectively does an in-place upgrade of your app. If everything is intact then (and there's no reason it wouldn't be), you should be fine.
When the app is upgraded your Documents folder is left intact. You can copy files into the Documents directory the first time your app is run such as a sqlite file for example, obviously only if it doesn't already exist. If you use CoreData then it will automatically store your data there. You will need to be able to run migration scripts if your data schema changes on upgrade, so keep that in mind. CoreData has migration features to take care of this for you and of course you can do it manually too.
When you run an app in the simulator it also leaves the Documents directory intact, so you have to delete the app from the simulator to simulate a fresh install. An upgrade is simulated simply by running your code since the Documents folder was created on the 'fresh install' first run.
Another way to approach this would be look at the Documents folder. If you are running your app in the simulator, then your app's Documents folder will have a path something like this:
/Users/itsaboutcode/Library/Application Support/iPhone Simulator/4.1/Applications/SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP/
If you are testing on an iDevice, then use Xcode's Organizer window's Summary tab. At the bottom there's a section called Applications. You app will be near the top of that list and it will have a toggle triangle - which you will click on. This will reveal "Application Data" which can be downloaded by clicking on downward pointing arrow to the right.
The iPhone Simulator has the advantage that the Documents folder and its contents can be modified at will. The Application Data on iDevice is read-only (except, of course, for your app at runtime).

Xcode, changing applications subfolder?

Hi have noticed today whilst writing a simple iPhone app that Xcode sometimes starts a new folder in applications, whilst your still working on the same app.
/Users/Fuzzygoat/Library/Application Support/iPhone Simulator/User/Applications/4E5EF4F0-F410-46A6-888C-0D23BB97D2DC
Does anyone know what causes Xcode to swap to a new app folder (i.e. the one named "4E5EF4F0-F410-46A6-888C-0D23BB97D2DC")
EDIT_001: One thing I have noticed is that I have been doing a lot of quitting an application and restarting to check a set of archive methods, and that does tend to confuse it sometimes. A couple of times it has not found saved data, I guess this is just a side effect of constantly running the simulator over and over via Xcode. Things seem to go just fine if I test on the Simulator without Xcode, for a start the folder keeps the same name.
NB: I am using NSSearchPathForDirectoriesInDomains to get the documents folder each time.
gary
For security reasons, iPhone OS restricts an application (including its preferences and data) to a unique location in the file system. This restriction is part of the security feature known as the application’s “sandbox.” The sandbox is a set of fine-grained controls limiting an application’s access to files, preferences, network resources, hardware, and so on. In iPhone OS, an application and its data reside in a secure location that no other application can access. When an application is installed, the system computes a unique opaque identifier for the application. Using a root application directory and this identifier, the system constructs a path to the application’s home directory. Thus an application’s home directory could be depicted as having the following structure:
/ApplicationRoot/ApplicationID/
During the installation process, the system creates the application’s home directory and several key subdirectories, configures the application sandbox, and copies the application bundle to the home directory. The use of a unique location for each application and its data simplifies backup-and-restore operations, application updates, and uninstallation. For more information about the application-specific directories created for each application and about application updates and backup-and-restore operations.
see The Application Sandbox
I know it happens when you restart the simulator. At least, that is when I have definitely observed it.
The developer docs tell you that the path can change without warning and to never depend on it. This is part of the iPhone's security system which prevents malicious apps from using hardcoded paths to find and exploit system resources.

iPhone Application Version Upgrade will remove file stored in iphone memory?

Currently I have my application in which I am creating some plist file in User's Device and storing some local data.
Now, my confusion is that what happen if i will launch next version of my application and once user will upgrade my application's current version then what happen with that plist file which is stored in Users iPhone Device ?
Thanks in advance...
When users update application only the application bundle changes and other folders in application sandbox should remain intact.So if you store your data in Documents folder then it will persist after application update.
Edit: See Files Saved During Application Updates section in "Application Development Guide"
Nothing will happen to the files stored in the App's Documents directory. They will still be intact after the app is upgraded.