Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleted CloudKit records Reappear

I'm building an iOS application using CloudKit.

It should allow a user to add, edit and delete Products in the cloud. The user can organize these in Folders. These folders are just other Record Types in cloudkit. There is no limit to the levels of folder the user can use, as any folder can just hold a CKReference to it's parent Folder. All CloudKit communication in my app happens in a dedicated CloudKitController Class

This all works, but stops working after a while for no clear reason.

When I test my app, I don't even user folders that are multiple levels deep. However, after using it a while (up to a week), All deleted records seem to reappear on CloudKit. A couple of notes on this:

  • When I reset my CloudKit dashboard and start all over again, it works perfect. No code changes made.
  • Obviously, I'm constantly editing my code as the app is in development. However, I generally don't edit the data types in my code that are to be stored in CloudKit. When I do, this issue does not arise straigt afterwards
  • Changes in the CloudKit Dashboard (e.g. adding data types) do not cause this issue
  • Am not storing any records locally, like in core data. They just sit in a singleton as long as I use them
  • When I go to CloudKit Dashboard, the Product Record Type shows it has e.g. 13 instances. Sometimes it's so bad, that my app actually loads over 100. I can also see them when I go to the recordZone, but still the RecordType says it only has 13 instances
  • Deleting these records in CloudKit Dashboard only makes them disappear for a while. When I reload the page, they pop up again.

It has been going like this for a while now, and I have checked my code, the Apple Library and google numerous of times but I cannot figure out what causes this issue.

Question: Would anyone know anything on how to overcome this issue? As I said, I've been running into this for weeks, and resetting my CloudKit dashboard only 'cures' it for up to a week, then it pops up again. I'd also be more than happy to post any code if that would help you answer my question. I haven't posted any code initially, as I have no clue what code might cause this.

Any answer would be highly appreciated

like image 378
Joris416 Avatar asked Jun 20 '15 03:06

Joris416


People also ask

Can I delete CloudKit metadata?

A user can delete your app's data on the CloudKit servers through iCloud Settings->Manage Storage. Your app needs to handle this gracefully and re-create the zone and subscriptions on the server again if they don't exist.

Does Apple use CloudKit?

Since CloudKit is deeply tied to Apple's operating systems and devices, it's not suitable for applications that require a broader range of device support, such as Android or Windows clients.

What is CloudKit on Mac?

Overview. The CloudKit framework provides interfaces for moving data between your app and your iCloud containers. You use CloudKit to store your app's existing data in the cloud so that the user can access it on multiple devices. You can also store data in a public area where all users can access it.

What is CloudKit core data?

Core Data owns the record ID for all of the objects that it creates in CloudKit. And, for each one, we will generate a simple UUID to use as its record name. When the Record Name is combined with a zone identifier you get a CKRecord ID. At the bottom, you'll see how Core Data manages type information.


1 Answers

This might happen because the dashboard trace below suggests Apple use the Tombstone technique for replicating deletes across a distributed database. One of the nodes might have a bug or an old software version and is syncing the tombstone false field back across the system, causing the record to undelete itself. Or maybe something your code is doing is accidentally bringing these deleted records back to life? A workaround would be to use your own soft-delete boolean field and see how that behaves.

[{
    "results": [{
        "tombstone": false
        "id": "NewItem",
        "etag": "ibgs5bpj",
        "recordType": "Items",
        "fields": {
            "name": "Malc",
            "location": {
                "latitude": 38.0,
                "longitude": -122.0
            }
        },
        "conflictLosersEtags": [],
        "created": {
            "timestamp": 1435514295943,
            "user": "_0ac573ae502ca7ca9d763a84b27bc42a",
            "device": "_2"
        },
        "modified": {
            "timestamp": 1435514295943,
            "user": "_0ac573ae502ca7ca9d763a84b27bc42a",
            "device": "_2"
        }
    },
    ...

As for the record counts, yes mine are inaccurate too.

like image 53
malhal Avatar answered Sep 30 '22 07:09

malhal