caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.94k stars 245 forks source link

crash in resumeLongLivedOperationIfPossible #262

Open Tliens opened 2 years ago

Tliens commented 2 years ago

please replace function resumeLongLivedOperationIfPossible like this

func resumeLongLivedOperationIfPossible() {
        container.fetchAllLongLivedOperationIDs { [weak self]( opeIDs, error) in
            guard let self = self, error == nil, let ids = opeIDs else { return }
            for id in ids {
                self.container.fetchLongLivedOperation(withID: id, completionHandler: { [weak self](ope, error) in
                    guard let self = self, error == nil else { return }
                    if let modifyOp = ope as? CKModifyRecordsOperation {
                        modifyOp.modifyRecordsCompletionBlock = { (_,_,_) in
                            print("Resume modify records success!")
                        }
                        // The Apple's example code in doc(https://developer.apple.com/documentation/cloudkit/ckoperation/#1666033)
                        // tells we add operation in container. But however it crashes on iOS 15 beta versions.
                        // And the crash log tells us to "CKDatabaseOperations must be submitted to a CKDatabase".
                        // So I guess there must be something changed in the daemon. We temperorily add this availabilty check.
//                        if #available(iOS 15, *) {
//                            self.database.add(modifyOp)
//                        } else {
//                            self.container.add(modifyOp)
//                        }
                    }
                })
            }
        }
    }
Tliens commented 2 years ago

It's work very well

Tliens commented 2 years ago

maybe self.container.fetchLongLivedOperation already did added this ope.