CKContainer.discoverAllIdentities always fails

前端 未结 1 1979
北海茫月
北海茫月 2021-02-14 23:20

The CKContainer.discoverAllIdentities request always fails in my CloudKit app. It has continually failed over the course of several days.

A simplified versi

相关标签:
1条回答
  • 2021-02-14 23:42

    Problem:

    This was a problem in iOS 11.0

    Based on my testing:

    This works ok in Xcode 9.2 / iOS 11.2.1 on the device (not simulator)

    After resetting the simulator works for the first time, doesn't work subsequently, however on the device it works repeatedly.

    Code:

    let queue = OperationQueue()
    
    func requestPermissions(for permissions: CKApplicationPermissions,
                            completionHandler: @escaping (CKApplicationPermissionStatus, Error?) -> ()) {
        
        CKContainer.default().requestApplicationPermission(permissions) { status, error in
            
            if let error = error {
                
                print("Error for requesting \(permissions) - \(error)")
            }
            
            let statusMessage : String
            
            switch status {
                
            case .granted:
                statusMessage = "Granted"
            case .denied:
                statusMessage = "Denied"
            case .couldNotComplete:
                statusMessage = "Could not complete"
            case .initialState:
                statusMessage = "Initial state"
            }
            
            print("Permission - \(statusMessage)")
            
            completionHandler(status, error)
        }
    }
    
    
    private func discoverAllUsers() {
        
        let operation = CKDiscoverAllUserIdentitiesOperation()
        
        operation.userIdentityDiscoveredBlock = { userIdentity in
            
            print("userIdentity = \(userIdentity)")
        }
        
        operation.discoverAllUserIdentitiesCompletionBlock = { error in
            
            if let error = error {
                
                print("Discover all users Error: \(error) ")
            }
            else {
                print("Discover all users completed successfully")
            }
        }
        
        queue.addOperation(operation)
    }
    
    0 讨论(0)
提交回复
热议问题