caiyue1993/IceCream

Crash with longLivedOperation iOS 15

Closed this issue · 11 comments

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
                    }
                })
            }
        }
    }
}

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

mrezk commented

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

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 which Xcode 13 beta are you using to build the app?

I used beta 5 to build, the problem persists

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.

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!

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

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

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:)

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

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