iCloud and Core Data - How to debug? - ios

I have an Library-style app which uses Core Data to store its data. Currently I am working on the integration of iCloud support.
I worked through several examples and the Apple docs and finally managed that an object created on device A is automatically synced to device B.
That is great but know I am experiencing the some problems: Some objects are synced and others are not and I have no idea how to debug this. Is there some way to "see" which data is transfered to iCloud, which data is stored in the cloud, and which data is downloaded from iCloud?
All I see at the moment is, that I create some NSManagedObject and store it to the ManagedContext/PersistentStore. I cannot see if it is transfered to the cloud and I cannot see the current content of the cloud. This makes it unpossible to debug the whole process.
So how to debug iCloud?
EDIT on 06/02/2015
I asked this question quite a while ago but it still gets some up votes or favorites. Therefore I would like to share some information I got meanwhile:
DO NOT USE iClOUD! I cannot tell you how many headacdhes and sleepless nights I had because of iCloud. It is jut not worth the candles. At least not when being used with Core Data. It just does not work reliably. This is even still true with iCloud Drive. My apps "supported" iCloud for about two years I did everything possible to get it running. Every time it seems to work I got new error messages from users. It worked fine for many users and caused trouble and even crashes for many othes. It was just terrible. Do your self a favour and use any other syncing service.

There seems to be a runtime argument
-com.apple.coredata.ubiquity.logLevel 3
check this article http://www.freelancemadscience.com/fmslabs_blog/2012/3/28/debug-settings-for-core-data-and-icloud.html?

tried the mitmproxy to see what is send and what is received?
There is a GameCenter tutorial at http://mitmproxy.org/doc/tutorials/gamecenter.html , it should be similar for iClound transfers.

Related

Share iCloud Key-Value Storage with app from other Developer

The question might seem weird (and stupid) at first, but keep reading...
I used iCloud Key-Value Storage in one of my apps and now I need to Transfer this app to another Developer Account. But it's, for some reason, impossible to transfer apps if they've used iCloud Entitlements (why no warning?!?!).
So...In other words, I need to remove my original app and create a new one in my new Developer Account. But before that happen, I want my existing users to be able to sync their data to a common iCloud Key-Value Storage, but directed at the new app "container".
If, the "new" app is Live, would it be possible to point at that app Cloud Container (from my old one)? (e.g. my old app saves iCloud data to the new container).
When reading my own question I just think "this sounds like a big security breach if possible", so my guess is, no. But there's nothing in the Apple Documentation that says that this is not possible.
I'm not interested in solutions that involves users saving data on an external db (I know this is possible, but not what I'm looking for right now). Is there some way to save the data locally on disk (without being removed when app is removed) and then read it from the other app?

Share database [core data] between different devices, not just the user's ones

What is the best way, to share a database between different devices, that are not just the user’s ones, but for example could be his friend’s phone. That means that iCloud is not an option.
Example:
 All of my data is app-user specific, so basically:
user logs into my app, do some work
then he can log in with the same acc on his friend phone and data should be the same
Is there an any way to upload the whole user specific database to some online storage provider (like firebase,… ) and then download it on another device and initialise core data stack, when the same user logs in on a different device?
Or is it the only way to sync data with the server and than preload the database?
You could simply upload the whole database file(s) and then download it on another device. The problem though is portability. You need to ensure that both devices support the same version of the database so they are compatible. To port the same thing to another platform is again a different story but doable when not using core data.
Then there is a problem of conflicts. Imagine you forget to log out from the second device and you open it after a week and the database is accidentally synced back to the server. This will make you lose all the data you created on your "main" device.
So in general it is possible to sync the whole thing but you will have loads of issues. You should create a server that supports all entities and works through ids (so you know the object was modified and not created) and date modified to be able to resolve conflicts.
Syncing data between multiple devices is the biggest reason to use something like Firebase. That's one of its primary purposes. You would use Firebase for data storage instead of Core Data, and it would automatically handle syncing between devices. You don't write code to upload or download anything, you just read and write Firebase data and it handles the syncing. It supports user accounts, so if a user logs on on a different device, their data automatically syncs to that device. There are numerous other options besides Firebase, of course.
CloudKit also syncs between different devices, but it's linked to the current iCloud account on the phone. Since you want in-app login, it's not so good.

CloudKit storing and restoring data when testing, app is now released and users are losing their data

I am using Swift. I can show my code if need be but there is a lot and it may be confusing and unnecessary (if you want to see if please let me know).
So my game needs to save things like high scores and purchases. When I am testing my app with Xcode, high scores get saved and I can delete the app, reinstall, and it pulls from CloudKit successfully. I submitted the application to Apple and they too found that the CloudKit purchase tracking system was working and let it go through to the app store. I told a few friends about my app and wanted them to test it a bit. For some reason though whenever they delete and reinstall the app all their data is lost! It is not performing the same way it does for me on Xcode (or for Apple for that matter).
The really annoying thing is that it takes 3-5 days for any updates I write to make it to the update and I can't even identify the problem yet because here on Xcode it works perfectly.
Does anyone know where the problem might lie? Where I might look in my code or places I could check?
Thanks!
Edit 1: Also a kind of follow up: A friend of mine is abroad and is always on airplane mode. When I check the CKContainerID on airplane mode when testing it finds the user perfectly. For him, however, it thinks that no user is signed in.
Why is all this different in production??
Edit 2: I'm finding some things regarding production cloudkit and development cloudkit? I am totally unfamiliar with this. Secondly I haven't messed around with the CloudKit Dashboard. My code basically tries to pull from the user's CloudKit and if it can't find those records then it will use the saveRecord function to create it.
Edit 3: Have just looked at this tutorial: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/DeployingYourCloudKitApp/DeployingYourCloudKitApp.html#//apple_ref/doc/uid/TP40014987-CH10 and when I have followed those steps to deploy schema I see that the "changes to record types" lists every record I have. Does this mean that there currently are no records for production meaning no one can save anything? Do I just need to follow all these steps to deploy to development and I'm okay? I'm not too sure what this does so I am hesitant to do so.
Figured it out! Refer to my 3rd edit. Basically my data holders were all in the development cloud thus when users tried to save/pull their data there wasn't anything in the production cloud for them to save to/pull from. By following that little Apple tutorial and essentially pushing my schema from development to production my users were able to store their data about 10 minutes afterwords!

iOS app trouble storing user's documents/photos anywhere other than the phone

I'm trying to find a way of letting a user store their photos/documents online for my app. They can upload these to the app after registering an email and they remain on the phone even when the user logs out and then in again. However if the user deletes the app, downloads it again (the developers are using TestFlight at the moment), and logs in, any photo or document that the user saved before deleting has vanished.
I've been told that the data hasn't been stored on the Kinvey SDK service that we have been using as it takes a while to upload the data and then was told the app would be better suited on Kinvey REST API as the SDK version doesn't support background mode which supposedly would help store the data quicker (but this still wouldn't be 100% sure the photos/documents would be stored)
I'm not a developer/coder so I'm afraid I don't know much technically but my app needs to be able to have access across devices for the user's photos and documents, if these are 'lost' it would be catastrophic.
Please could someone help me if there a way of doing this?
Thank you.
Well If you want to save pictures or data that do not get deleted here are few options.
Save them iPhone,iPad gallery if not the use REST API
"Kinvey" can be used for that.
The alternative of "Kinvey", Kindly look into this.
https://www.raywenderlich.com/126098/top-5-parse-alternatives.
and may be you can try this. It provides chat feature too.
http://quickblox.com/

How do I cache Firebase data for offline usage?

I build apps that bundle up JSON data. I want to switch to Firebase as my backend, but I need to ensure I can access the data even if firebase is offline. There's no guarantee that the user will have an internet connection at the time they launch the app. The data consists of a fairly large JSON blob.
I heard that firebase does cache data on iOS for offline access, and that's great. I just need to know how to bundle the data for that first time the app is ran, so the user can use the app prior to getting to a network connection.
As it sounds like you discovered, the Firebase Obj-C client does have beta support for offline access / disk persistence. Details can be found here.
But that doesn't address your desire to "seed" the app with initial data so that it has data available before the app has ever been able to connect to Firebase. Unfortunately, there's no direct support for that.
One hacky solution you could attempt with Firebase is to just do a setValue with the data in question, in order to seed the cache. This should work but will eventually try to write that data to Firebase, when the app gets connected, so you'd probably want to have security rules to prevent the user from actually modifying that data. As I said, it'd be a hacky solution.
For now it might be best to just handle this with special logic in your app that pulls data from some other data source (hardcoded values or an embedded file or whatever) until the first time you get data from Firebase.
Sorry there's no direct support for this at the moment. We'll take a look to see if we could support this more directly in the future.

Resources