Cloudkit 身份验证仅适用于我的 alt 帐户,不适用于 Dev 或 Tester 帐户

Cloudkit Authentication Only works on my alt account and not Dev or Tester accounts

我注意到在模拟器或物理设备中测试我的 cloudkit 应用程序时,我只能使用我的 alt 帐户保存记录,而不是我用来创建 app/container 的开发帐户。当我去保存时出现错误:

Error saving record <CKRecordID: 0x9t83ecb31790; recordName=8AB667FA-0D8F-4B72-8B90-C694AB960EFF, zoneID=_defaultZone:defaultOwner> to server: CREATE operation not permitted

具体错误代码为10当运行

if let error = error as? CKError { print(error.errorCode) }

这表明存在权限问题。 cloudkit 仪表板中的所有安全角色都是正确的。我确认用户已通过 cloudkit 对所有帐户

进行身份验证
CKContainer.default().accountStatus { (accountStatus, error) in
        switch accountStatus {
        case .available:
            print("iCloud Available")
        case .noAccount:
            print("No iCloud account")
        case .restricted:
            print("iCloud restricted")
        case .couldNotDetermine:
            print("Unable to determine iCloud status")
        }
    }

它在 Apple Reviewer 端也不起作用,他们已经因为这个错误拒绝了我的应用程序。这意味着它不仅是我的 Dev 帐户不起作用,它似乎是除了我的 alt 之外的所有东西。这看起来很奇怪。

这是我的保存代码:

static func saveUser(user: UserElement, completion: @escaping (Result<UserElement, Error>) ->
    ()) {
    let itemRecord = CKRecord(recordType: "userInfo")
    
    itemRecord["uniqueID"] = user.bossID as CKRecordValue
    itemRecord["screenName"] = user.screenName as CKRecordValue
    itemRecord["shareCode"] = user.shareCode as CKRecordValue
    itemRecord["subscribedBosses"] = user.subscribedBosses as CKRecordValue

    let container = CKContainer(identifier: "iCloud.Caz4Short.WatChaDoin")
    container.publicCloudDatabase.save(itemRecord) { (record, err) in
        DispatchQueue.main.async {
            if let err = err {
                print("error on run")
                completion(.failure(err))
                return
            }
            
            guard let record = record else {
                print("record")
                completion(.failure(CloudKitHelperError.recordFailure))
                return
            }
            
            let id = record.recordID
            guard let boss = record["uniqueID"] as? String else {
                print("record ID")
                completion(.failure(CloudKitHelperError.recordIDFailure))
                return
            }
            guard let name = record["screenName"] as? String else {
                
                print("screenname")
                completion(.failure(CloudKitHelperError.castFailure))
                return
            }
            guard let bossCode = record["shareCode"] as? String else {
                print("Code")
                completion(.failure(CloudKitHelperError.castFailure))
                return
            }
            guard let subs = record["subscribedBosses"] as? [String] else {
                completion(.failure(CloudKitHelperError.castFailure))
                return
            }
            let element = UserElement(recordID: id, bossID: boss, screenName: name, shareCode: bossCode, subscribedBosses: subs)
            completion(.success(element))
        }
    }
}

这是 CloudKit 的错误。有时容器显然会在创建时损坏。

我能够通过在 Xcode 中创建一个新容器(在您的应用程序的配置屏幕上)并取消选中旧容器来修复它。然后我从头开始配置新容器,添加所有数据类型并配置安全角色(角色需要大约 5 分钟才能启动,所以只需保持 checking/trying)。