Is it is necessary to copy my local Database.sqlite to Documents directory in ios environment?
If Yes .,then please explain or refer link..
You need to copy it because if you put it on your app main bundle, it will be readOnly, and that's not what you want. So you must copy your .sqlite in Documents directory, or whatever directory where you have write permission.
Related
I did some research about backup files and data in iCloud and I was wondering if the Core Data would get saved in an iTunes backup if i would not use any iCloud functionality.
So i got an application with recent server connections saved in core data to fill it back into a UITableView. If i make a device backup with iTunes and restore it later on another device would the recent connections still show up?
None of the Q/A I found did explicit answer this question.
Another question besides: Is it possible to try these itunes-backup things with an app which is in developement?
This depends on where you save your core data database.
In general the Library and the Documents directory are backed up by iTunes (and by iCloud), tmp and Caches are not backed up.
See: Apple Documentation - iOS Standard Directories: Where Files Reside
AppName.app
This is the app’s bundle. This directory contains the app and all of its resources.
You cannot write to this directory. To prevent tampering, the bundle directory is signed at installation time. Writing to this directory changes the signature and prevents your app from launching. You can, however, gain read-only access to any resources stored in the apps bundle. For more information, see the Resource Programming Guide
The contents of this directory are not backed up by iTunes. However, iTunes does perform an initial sync of any apps purchased from the App Store.
Documents/
Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.
The contents of this directory are backed up by iTunes.
Documents/Inbox
Use this directory to access files that your app was asked to open by outside entities. Specifically, the Mail program places email attachments associated with your app in this directory. Document interaction controllers may also place files in it.
Your app can read and delete files in this directory but cannot create new files or write to existing files. If the user tries to edit a file in this directory, your app must silently move it out of the directory before making any changes.
The contents of this directory are backed up by iTunes.
Library/
This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories.
Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.
The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes.
For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.
tmp/
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
The contents of this directory are not backed up by iTunes.
I have created the application which is based on Sqlite database.
So in my app, initially i have created the Sqlite db with one data and i have added that db into my "Resource" folder in my project.
While app running at first time, checking db in Documents folder(Sandbox) if no file means, copy the db from Resource to Document folder.
After that every insert and delete operations performing on Db in Document folder only. not on db in Resource folder.
So, i have inserted 50 items in db and then i have deleted the app from Simulator(or) device.
When deleting app, db also deleted with that.
My question is ==> How to overwrite the Sqlite db(in Resource folder) with db(in Documents folder) when every updation in app(insert, delete)?
because db file in Documment folder getting update while inserting items into that.
I am using XCode 4.2 with iOS 5 sdk.
You cannot change the Resource bundle once you created (i.e app file). You cannot overwrite the SQLite db into resource folder of your bundle.
If you still want to keep previous db then just copy it from simulator path and replace whenever you clean and build the app.
EDIT:
You can go to /Users//Library/Application Support/iPhone Simulator/"Simulator version you use"/Application/"check all folder to find your app inside this folder"/ "YOUR APP.app"
Then Right Click APP file and Click Show Package Content. Now you will be able to see the resources you used in App file. You can search your DB and BACKUP/REPLACE it.
First off the database file in the app bundle (resource folder) is read only and can't be changed by the app.
Second when an update is installed, all the files in the app bundle get replaced by the files in the update. The files in the document directory aren't touched.
if you need to update the database file in the document directory you will need to implement an update method some where and keep track of the versie of the database used.
There is no way you can modify any resource present inside the application bundle.That's why we copy the database file to the documents directory of the application, so we can modify the file. If you want to preserve data, you backup the data using the iCloud service.
You have to do this by opening another handle for the database in your resource folder and perform the operation for that too. I assume you need it only when you run it in simulator for convenience.
You cannot do this when you run in device.
Its true that there is no way to copy that document folder data again to resource bundle, so i will suggest u to take a backup of that db before deleting the application from simulator or from the device.
I'm reading through some of the documentation about File Management on iOS. When you create an application for the simulator, does the application get created somewhere on my hard drive? If so, where is it?
Also, does this have access to the Documents directory? Like if I create some test .txt file, and want to see it in the App->Documents folder, is that possible? Thanks.
Yes. Look here:
~/Library/Application Support/iPhone Simulator/4.3.2/Applications
Change the 4.3.2 to be the version of the Simulator you are using.
Within that folder you will find your apps, except the they are named cryptically. Open one of those folders and you will find your app, named as you recognize it, and the Documents, Library and tmp folders. Documents is where you find the docs that your app creates and uses. You can, in fact, makes changes to the files in the Documents folder or just access their content to see what your app sees or writes.
Under XCode 6, the document directory for your app is quite hidden:
~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//
You can find the directory for your app with this command:
$ sudo find ~/Library/Developer/CoreSimulator/Devices -name <APP_NAME>.app | grep -o '.*/'
I have created a script that saves some files in the Documents directory of my app. Now I need to copy these files into my "application.app" bundle...
How I can do this? Thanks to everyone that can help me.
The .app bundle is code signed, you can't change its contents afterwards
so I am working on a jb app that requires writing to the file system (/var/mobile/Library/Downloads specifically), and I tried hard coding it in like someone recommended but I cant seem to make it work, i know how to do so to the Documents directory in my app but not the file system, any ideas? thank you!
edit 1 - as reference: the way that the Safari DL Plugin does it
try this path
/private/var/mobile/Library/Downloads
You need to check if the directory already exists or not before writing to it. You can use NSFileManager class for file/directory operations. You also need to check for the permissions on that folder, your app if not running as root cannot write to folders which only root has access to.