CloudKit fetchRecordChangesOperation给出了一个" AppDefaultZone不支持同步语义"

时间:2014-09-11 00:08:03

标签: ios objective-c cloudkit ckfetchrecordchangesopera

我正在使用带有CKFetchRecordsChangeToken的CKFetchRecordChangesOperation来获取更改,它告诉我“AppDefaultZone不支持同步语义”。

以下是有问题的代码:

- (void)downloadServerChangesWithCompletionBlock:(void (^)(NSError *error))completionBlock
{
    // Prepare to fetch remote changes
    CKDatabase *database = [CKContainer defaultContainer].privateCloudDatabase;
    CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:CKRecordZoneDefaultName ownerName:CKOwnerDefaultName];

    // Initialize fetch record changes operation
    CKFetchRecordChangesOperation *fetchRecordChangesOperation = [[CKFetchRecordChangesOperation alloc] initWithRecordZoneID:zoneID previousServerChangeToken:[self changeToken]];
    fetchRecordChangesOperation.recordChangedBlock = ^(CKRecord *record) {
        [self performRecordChange:record];
    };
    fetchRecordChangesOperation.recordWithIDWasDeletedBlock = ^(CKRecordID *recordID){
        [self performRecordDeletion:recordID];
    };
    fetchRecordChangesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *error) {
        if (error) {
            completionBlock(error);
        } else {
            [self setChangeToken:serverChangeToken];
            completionBlock(nil);
        }
    };

    // Perform the operation
    [database addOperation:fetchRecordChangesOperation];
}

这是打印出来的错误

[PBCloudKitSyncManager] Error Downloading Data:
<CKError 0x157a2500: "Server Rejected Request" (15/2027);
server message = "AppDefaultZone does not support sync semantics";
uuid = [redacted];
container ID = "[redacted]">

1 个答案:

答案 0 :(得分:2)

我通过切换到自定义区域来解决问题。我在初始化CloudKit时创建了区域,当我初始化zoneID时,我使用它:

CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:@"Custom Zone Name" ownerName:userRecordName];

其中userRecordName是我在Cloudkit初始化中调用此方法时为用户获取的CKRecord的记录名称:

[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
     if (recordID) {
         // Save the user record id
         [self saveUserRecordName:recordID.recordName];

          /...

      }
}];