caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.93k stars 243 forks source link

Crash with longLivedOperation iOS 15 #244

Closed alxrguz closed 2 years ago

alxrguz commented 2 years ago

Good afternoon, with the arrival of iOS 15 beta 4, there was a problem during synchronization and it seems that it will not go away. When SyncEngine is initialized, the method is called resumeLongLivedOperationIfPossible, which causes the application to crash. The crane happens when trying to add longLivedOperation in container, reason:

Terminating app due to uncaught exception 'CKException', reason: 'CKDatabaseOperations must be submitted to a CKDatabase

I attach the library code and the place of departure

final class PrivateDatabaseManager {

    let container: CKContainer
    let database: CKDatabase

    public init(container: CKContainer) {
        self.container = container
        self.database = container.privateCloudDatabase
    }

    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!")
                        }
                        self.container.add(modifyOp) // CRASH HERE
                    }
                })
            }
        }
    }
}
aaronpearce commented 2 years ago

Disabled isLongLived = true can help with this, but it seems that it may possibly break deletions.

mrezk commented 2 years ago

@alxrguz which Xcode 13 beta are you using to build the app?

alxrguz commented 2 years ago

Disabled isLongLived = true can help with this, but it seems that it may possibly break deletions.

Thanks, I'll try, but what about the operations that have already been answered with this flag? And what else do you think it might affect?

alxrguz commented 2 years ago

@alxrguz which Xcode 13 beta are you using to build the app?

I used beta 5 to build, the problem persists

caiyue1993 commented 2 years ago

Hi guys, there must be something changed in the daemon code of iOS 15 beta version. I've proposed a PR #247 to resolve this issue. You could give it a try like I do. And if the problem still occurs in the later iOS 15 GM version, please let me know and I'll merge that into the master branch. Thank you.

kenton7 commented 2 years ago

Hi guys, there must be something changed in the daemon code of iOS 15 beta version. I've proposed a PR #247 to resolve this issue. You could give it a try like I do. And if the problem still occurs in the later iOS 15 GM version, please let me know and I'll merge that to the master branch. Thank you.

It helped. Thank you!

alexeydemidovkz commented 2 years ago

Hi, this is still crash on the iOS 15 RC and Xcode 13 RC, thank you.

caiyue1993 commented 2 years ago

If the problem still occurs I suggest you guys add the if-else to make the code inside resumeLongLivedOperationIfPossible only available before iOS 15.

alexeydemidovkz commented 2 years ago

If the problem still occurs I suggest you guys add the if-else to make the code inside resumeLongLivedOperationIfPossible only available before iOS 15.

Yes your PR fixes the issue thank you for that one. You just mentioned that it needs to be tested on GM before merging so this was just this:)

caiyue1993 commented 2 years ago

@alexeydemidovkz That's nice! Then I'll merge #247 very soon. Thanks for your feedback. Appreciate it 😉

caiyue1993 commented 2 years ago

247 has been merged to fix this issue. Thank you guys!