Ideal location of db on IOS - objective-c

I am using phonegap for IOS app development. Now, phonegap tries to find the db by default in 'NSCachesDirectory', but whenever IOS runs into memory problems, it tries to delete data from 'NSCachesDirectory', so, the data is not secured. If i am not mistaken, this problem was solved in cordova 2.1.0, where the back-up of data is taken and then restored afterwards. So, just wanted to confirm if i am heading in the right direction or data itself can be stored in 'NSDocumentDirectory' so that data is secured and somehow phonegap looks for db in 'NSDocumentDirectory' and not Caches direcory. Thanks.

Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory(You can store DB in Documents directory)
Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory.

Related

UIDocument VS CoreData External Binary Data VS File Manager

I have an iOS 7 app, that is using Core Data. Some of the Core Data objects has a related (one to one relationship) images that are > 1MB & < 4MB and are stored in the app’s Document folder. Core Data objects only stores image names as string.
I want to integrate iCloud support for the app so I can sync data between devices. I am planning to use iCloud Core Data storage to sync Core Data objects. But what to do with the images?! After reading different posts, I found a couple of options that are highlighted underneath. I am struggling to pick one, that would suit me best. It would be nice to know someones experience/recommendations. What I should be careful with, or what didn't I think of? I also need to consider migration of the existing data to the option I will pick.
OPTION 1. Store UIImage in the Core Data as Binary Data with External Binary Data option (read here). At this moment is seems to be the easiest solution, but I guess not the best. From Documentation:
It is better, however, if you are able to store BLOBs as resources on
the filesystem, and to maintain links (such as URLs or paths) to those
resources.
Also will the external files be synced? If so, how reliable the sync would be if the user quits on minimises the app, will the sync process resume? From objc.io about External File References:
In our testing, when this occurs, iCloud does not always know how to
resolve the relationship and can throw exceptions. If you plan to use
iCloud syncing, consider unchecking this box in your iCloud entities
OPTION 2. Store images using UIDocument (good tutorial here) and somehow track relation between Core Data entry and UIDocument. From what I understand whatever I put in this directory will be automatically synchronised to the iCloud by a system daemon. So if the user quits the app, the images will still be synced to the iCloud, right?
OPTION 3. Using FileManager(more info here). I haven’t read a lot about this approach, but I think it can also work.
OPTION 4. Any other?
There are similar posts (e.g. Core Data with iCloud design), but unfortunately they don't fully answer my question.
Seems Apple will reject application because of large database iCloud synchronization.
I think the best solution is to store images on a remote host, and keep Image URL in CoreData.
And also Local path of image should be resolvable from remote URL.
So the algorithm will look like this ->
1) Getting Remote URL from CoreData.
2) Resolve local path of image.
3) If local image exists retrieve it, otherwise read it from remote and save it to local storage.
You can have a look to Amazon S3 server here.

In Titanium Alloy, does the default database backup to iCloud automatically?

I've created an app that uses the Alloy framework to store data. I've found that the default Alloy database that gets created is called _alloy_.sql and is stored in the app's [APP_ID]/Library/Private Documents in the iPhone Simulator.
I was looking around on how to get this database backed up on iCloud, so that the users data would stay with them from device to device. But all the questions I found online where about turning this feature off, please see Support turning off iCloud backup for auto-generated model databases.
I have a few questions around this:
Does this mean that the default Alloy database is already backed up on iCloud?
Is there a way to confirm that this is the case?
How do I test that it is successful?
Should my app appear inside the iCloud settings section of the iPhone settings?
The Alloy database is exactly the same as every other database that you can create using
Ti.Database.open("db_name"); // _alloy_
or
Ti.Database.install("db_name"); // _alloy_
And it should be backed up by default ,so yes you are right it is already backed up.
You can find out more here https://developer.appcelerator.com/question/163013/icloud-backup-and-restore

How do I keep my database in sync with TICoreDataSync?

I've been working on this problem for a while now. Here's what happens:
My app is launched. It already has existing data in the core data store. It then connects to Dropbox using TICoreDataSync.
Then I connect a second device, which also has existing data. I connect it up to Dropbox the same way.
What then happens is that when I sync, it syncs data between the two harmoniously. Any changes i make on one device are sent to the other after a sync on both devices. The problem is, I want the existing data in the database to be uploaded to Dropbox and included in the sync, so both devices have all data.
How can I do this?
This is actually not how TICoreDataSync was intended to work. It will not merge those two store files for you, but will rather pull down the store file uploaded by the first device to the second device and then keep those store files in sync. From your description it sounds like you are skipping the whole store upload and download steps during sync manager registration.

Does updating app in iTunes loses the previous files and data stored in app

I have an iPad application which saves the files in it and i have release it in appstore. Now if the update the app does my previous files in that app gets deleted.
the document folder is not modifyed, so depends of what data you are interested in... I mean, the resource bundle is overwritten, so you can't ADD resources incrementally, but if yousaved some data in Document you'll find them also after update.

Pre loaded database on iPhone?

I developing an app that is read-only. The data has relationships, so I cannot just use a plist or something similar.
Questions:
Should I use Core Data for such a requirement?
If so, how would I enter the data and then release the app with that data?
How would I make it so that the app doesn't need to re-populate a DB every time it loads?
Is there a way to create a Core Data model using sql commands with sqlite (i.e. insert into, etc)?
You may use an SQLite database to accomplish this.
Create the model in your iOS app.
Create and populate the database in a Mac OSX utility command-line app
Copy the sqlite file into your iOS app and link it with some code
Work through these two tutorials, line by line, and afterward you will have a good enough understanding (and code sample) to complete this task in your own app.
Core Data on iOS 5 Tutorial: Getting Started
Core Data on iOS 5 Tutorial: How To Preload and Import Existing Data
In my short experience with the iPhone, you have two options.
Write a data import function and run it on the first application launch.
Use solution 1, but build the initial sqllite file in the simulator, and then on first application launch, copy it into the app's documents directory.
From past experience, option 2 is much quicker for user experience, and the preferred solution.
You can write a utility project that imports the app's data model and use throwaway code n that project to populate the Core Data DB. Once the DB is populated, simply copy the actual file to the app project's resources folder and then when you set up your persistent store, use NSBundle to return the path to the DB file within the built app.
And you're done.