Simperium for syncing binary data using Core Data? - ios

I'm using Simperium to sync instances of my app's data between each other. I went with this over iCloud because I've heard iCloud has a lot of issues with Core Data and as a novice to iOS, I believe Apple makes you pay to use their services (in a form of developer membership). Since my project is academic, there isn't a need for this.
I've set up Simperium to sync data from my app to their servers, and it's syncing well, but it seems it doesn't have support for binary data. My application syncs items and wishlists, and an item always has an image associated to it. The thumbnail I store in Core Data, since it's small (75x75), and the large image using NSFileManager. None of these sync.
Is it possible to enable sync for binary data and/or images stored in the app's sandboxed documents folder using Simperium? I've heard it's experimental, but if it works decently, I'll be glad to enable it. If not, are there any other frameworks that use sync and don't require iCloud to sync Core Data with binary data?

Syncing binary data isn't yet officially supported by Simperium, but you can track this GitHub issue for it. At the moment it won't work experimentally, either.
One strategy that some other developers are using is to sync filenames using Simperium (since they're just strings), and then deal with the corresponding data files on your own, either manually or with the help of another system like Amazon S3.

Related

How can you store data in such a way that they are not lost after deleting then installing the the ios?

Can core data do the job or should I use sqlite?
In general, applications on iOS run in a sandboxed environment. That means, you can only manipulate with things in your sandbox. However, when app is removed, so is the sandbox. Even if you install the application again, it will be completely clean. The only storage which is persisted across multiple installations of the app is Keychain, but it is storage purposed for sensitive data like passwords, certificates etc.
CoreData is basically a SQLite wrapper, which means that the backing SQLite database (file) is stored in the application sandbox.
If you referring to reinstallation of the whole iOS operating system, you can first create a backup which you can recover later and the data should be restored.
But, if you are talking about persisting data while reinstalling your app, you need to look into how to store them on remote storage (can be iCloud, Realm Cloud etc, your custom API/backend) and synchronize them to some remote storage.
I recommend you to look into CloudKit (iCloud API) as it is Apple platform and possibly purposed for what you are looking for.
Core Data uses SQLite under the hood as a default, so your question is wrong a bit.
I will try to give you an answer, if deleting then installing the the ios means deleting application and installing it again. Your application runs in a sandbox, so all the data you have in your DB will be removed after uses reinstall it.
If you want to persist it:
You must have some remote storage
If chunk of data is small, you can store it in keychain.
Hope it helps

Best practice for syncing Core Data database with images to Dropbox via ParcelKit

I have an iOS app that uses Core Data and ParcelKit to sync with Dropbox. However, the Dropbox Datastore API only allows records of 100K so it will not sync images that I store in the database. Any other workaround than storing images as separate files with filenames stored in the base? It is a little fragile when user can alter the content of the imagefile-folder thus braking the link to the database.
You should not store large images in the Core Data persistent store. Apple recommends that you should only store small images, such as thumbnails, perhaps 20K max. If you go beyond that, performance will eventually degrade significantly.
Thus, you cannot really avoid storing the images in separate files and storing their name/location in Core Data. This is the recommended pattern.
I do not see why you think this is fragile. Presumably you will store the images in the app sandbox there is no way the user can fiddle with them unless the iPhone is jailbroken.
The Dropbox sync should be managed independently from this setup.
FYI Dropbox just killed the Datastore API and will take it off line in 2016. :-(
You should monitor this ParcelKit Issue:
Dropbox Datastore is Deprecated #34
https://github.com/overcommitted/ParcelKit/issues/34

iCloud with Core Data and File sync

I'm working on an Application that uses Core Data with iCloud (with the great improvement given by iOS7). This application stores data to describe a task with this information:
name a NSString
date a NSDate
image a NSString which describes a path to the picture
The pictures could be stored in Documents or Library Directory (I have to decide which is the more convenient folder), by the way, in the same folder with a unique name.
Now I'd like to activate iCloud sync for the images too otherwise the experience of the user will be incomplete (I just sync DB data.. no images, a strange/wrong behaviour for an app).
I'm really confused by Apple Documentation. I can't find a way to understand exactly how iCloud data works for this kind of needs. I just want to sync every file of a folder as soon as they will be created. So my questions are:
Could you share some good resources to learn how to use iCloud for file sync
Have I to use UIDocument and other iCloud API? or is there something "automatic". Quite a new bye/stupid question, I know :(
Are there any problem using Core Data and Document based iCloud synch in the same app?
Note: I know that I can sync data just by adding file in the document folder and hoping that users activate document sync... but this is not what I want obviously.
It is pretty straight forward to use both Core Data transaction log synchronisation and file based synchronisation in the same app to achieve what you want to achieve.
So you would set up your Core Data stack to use iCloud options and synchronise data changes via iCloud. At the same time you would store your images in the Apps iCloud container so they get synchronised as well. Just remember you need to use a relative reference to the images in your Core Data fileURL because the full pathname will vary depending on the device the app is running on. So for example you would just store the image filename in Core Data and use a standard directory such as 'iCloudContainer/Documents/Images/' to store them. 'iCloudContainer' being the URL you get by calling the [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:] API.
I have uploaded sample Core Data apps that use iCloud for transaction log synchronisation (i.e. synchronising data in Core Data) and that use file synchronisation for storing Core Data backup files in iCloud which can then be accessed by any device. You should be able to use the same code for moving backup files to and from iCloud for your images. Just remember you have to trigger download of files from iCloud before you can use them either by doing a coordinated read or by initialising the download using NSFileManager.
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/sample-apps-explanations/
Download and run the sample apps and use the built in Backup File Manager to make backup files and to copy them to and from iCloud using different devices. Then just use the same code when storing your image files.
Your App does have to handle things like the user changing iCloud account, logging into or out of iCloud etc. and them move the core data file and image files accordingly.
The only way to have this happen automatically is to create a binary data attribute in your model for the images. If you do this, you will probably want to check the external binary storage allowed option, so the photos end up stored as files and not in the database.
If you would rather store the photos external to your store, you will have to do more work. You will need to migrate the photos into the iCloud container yourself, using the NSFileManager methods, for example. You could also use a class like iCloud Access if you find that easier.
The downside to handling the photos yourself is that you can never be sure that they have all arrived on your device when the Core Data store syncs, so it could be one or more photos are missing, even though there are entries for them in the store. You would have to make sure your app could handle this scenario, perhaps showing a placeholder image until the real photo was accessible.
There are no issues using Core Data and Document syncing in one app. In fact, they are exactly the same under the covers. From iClouds point of view, they are all just files to be transferred.

How to sync application data and core data on iOS devices?

I need to sync application on a few iOS devices. My app manages audio, video and images data(up to 50 Mb). I'm using core data to save media files filesystem paths locally. But how do I should save media to sync with other devices? I thought about storing all data (including serialized to NSData all audio, video, image files) in core data and using core data with iCloud together... But I think it bad practice... Also I thought about storing all media files in iCloud using NSFileManager's api but how do I now when new files will come...
Please give me advice in solving my problem.
It might be worth considering DropBox's Sync API for iOS-
https://www.dropbox.com/developers/sync/start/ios
They've implemented a solution for syncing files that, while it may not be a viable commercial option for your project, it's free to experiment with and the code is worth taking a look at to get some ideas.
OR
Your app could intermittently poll your own server or iCloud to check for updates (on startup, every hour, etc).
Apple also has Push notifications, while pretty reliable, there's no guaranteed delivery of every message, so polling might be the surest way to check sync.

iCloud + Preloaded CoreData

I have database with some default content. How can I use iCloud to sync changes in database on different devices?
I know how sync devices if CoreData was empty first and I can migrate from external sqlite file to CoreData.
If you have an existing Core Data store and you want to add iCloud support, you'll need to transfer all of your existing data to a new data store and save the result. This is necessary because iCloud only generates transactions when you save changes-- so you need to effectively save changes for everything to jumpstart the syncing process.
In most cases you can do this in a single step by using NSPersistentStoreCoordinator's migratePersistentStore:toURL:options:withType:error:. Pass in the same iCloud options that you would use when calling addPersistentStoreWithType:configuration:URL:options:error:. Use this alternate approach only when moving from a non-iCloud data store to one that does use iCloud.
Also, beware of using iCloud with Core Data. It has not earned a reputation for reliability. Pay close attention to Apple's documentation and sample projects, and even then be prepared for it to just not work sometimes.

Resources