我的CloudKit应用程序中的CKContainer.discoverAllIdentities请求总是失败.它在几天的过程中不断失败.
private func getContacts(completion: (([CKUserIdentity]?) -> Void)?) { container.status(forApplicationPermission: .userDiscoverability) { [weak self] status,error in if let error = error { print(error) } switch status { case .granted: self?.discover(completion: completion) default: print("status not granted") } } } private func discover(completion: (([CKUserIdentity]?) -> Void)?) { let op = CKDiscoverAllUserIdentitiesOperation() op.qualityOfService = .userInitiated op.discoverAllUserIdentitiesCompletionBlock = { error in if let error = error { print(error) } } op.userIdentityDiscoveredBlock = { identity in print(identity) } op.start() }
它会导致错误传递给op.discoverAllUserIdentitiesCompletionBlock.日志中的错误描述是:
< CKError 0x1c4a51a60:“服务器拒绝请求”(15/2000); server message =“内部服务器错误”; uuid = F67453B9-712D-4E5E-9335-929123E3C978; container ID =“iCloud.com.huntermaximillionmonk.topdraw”>
问题:
原文链接:https://www.f2er.com/swift/319440.html这是iOS 11.0中的一个问题
根据我的测试:
这在设备上的Xcode 9.2 / iOS 11.2.1中工作正常(不是模拟器)
重置模拟器后第一次工作,随后不起作用,但是在设备上它重复工作.
码:
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) }