Firebase offline mode store image - ios

I was trying to Store data offline by using firebase database reference. I read documentation and it say one line code will store everything.
Database.database().isPersistenceEnabled = true
But this line only store text. It's not storing image offline.

isPersistenceEnabled is only storing your text content. if you want to save image you need to use core data. Core data is little bit hard to save large file. i would recommend to use NSfileManager to Store your image.
Hope it will help .

Do you want to send data after you will be connected to WiFi? So you can store your data to CoreData and after you will be connected to Wifi send it to Firebase storage

Related

Upload image to firebase realtime Database or storage?

I am trying to upload images to firebase along with other string and double data type.
I am think about 2 options now, one is uploading the imageUrl to firebase Realtime Database and when I retrieved it, I will retrieve a imageUrl and convert it to image.
Another way is to upload the image file to Firebase storage.
Which one is the preferred one to do? From the speed of loading image? or other factors that I haven't thought of.
Thank you for your help! I appreciate it.
Don't store large binary objects in Realtime Database. Use Cloud Storage instead.
Upload image urls is a better option.
Upload the image is a heavier task, hence it is better to upload urls with other data.
It depends on how big your app is going to scale. However, storing a large binary files in real time database is not a good practise. I would suggest you to use cloud storage, usually AWS buckets to store images and save the URL to firebase, to retrieve it later.
Storage is given from firebase to store all your large data and then fetch asynchronously. So using storage should be a better way rather than database.
For any kind of file you must have to use storage, and then store only file name in your realtime database to maintain good performance of your application. And that is the main reason firebase provide those functionalities in separate ways.

Parse Local Data Store Inconsistency

I am facing an inconsistency on Local Data Store on iOS , that 4 out of 10 attempt will be unable to retrieve the pinned data and get Error: This object is not available in the offline cache. When I request and pinned the data , it was available , but after few load, then the data was not able to retrieve, there is no code changes nor data updates, purely playing around offline. (I am unable to track this , because this occur inconsistently ).
Please kindly assist in troubleshooting this or suggest what should I do with it. I am using Local Data Store to store all major data of my app, and also did download the images related after pinned, I wonder is it because of storage limit by parse ? or something like auto clean out the pinned object ?
You say that you are using Local Data Store for all the major data in your app. I presume you are using PFFile for the large data (like images), as per Parse's recommendation. If so, these do not persist in local datastore.
See here : pffiles in local datastore

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.

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.

iOS Saving Web Service Data to Device

My situation is that I have a universal app that talks to an sql database via odata. When the user retrieves data over the line I want to save that to the device so that if the user stops the app or the app crashes than I can rehydrate the saved device data and we will not have to re-retrieve the data when the app starts again.
My question is for this sitatuation is it more beneficial to user coredata to save the data to an sqllite db or should I save the data to the documents directory? The data can be serialized into an NSData object which could be saved straight to the device from what I have read, where as saving NSData objects to sqllite is not what it is designed for.
Im looking for the most performant of the two options and also the option that will not restrict as much on size restrictions.
Looking forward to any advice that you can give me.
Thanks in advance
If the size of the data is small enough to fit in memory with no problems, then you will probably get the best performance from serializing an NSData object.
If, however, the data reaches the point where it strains memory usage, you will want to use something like Core Data or sqlite to persist it to the disk and only load objects in memory you are using at the moment.

Resources