gpt4 book ai didi

ios - Azure 移动服务脱机数据同步 - 提供的项目无效

转载 作者:行者123 更新时间:2023-12-01 17:50:45 25 4
gpt4 key购买 nike

我正在使用 Azure 移动服务作为 iOS 应用程序的后端。我已将所有内容设置为离线同步,即使没有网络连接,我也可以查看、添加或修改数据。我现在正在进行测试,当我尝试同步数据时遇到错误:“提供的项目无效”。

这就是我正在做的事情:

我将一个新运动员添加到syncTableWithName:@"Athlete",如下:

NSDictionary *newItem = @{@"firstname": @"Charles", @"lastname": @"Lambert", @"laterality" : @"Orthodox"};

[self.athletesService addItem:newItem completion:^{
NSLog(@"New athlete added");
}];

这是 addItem 函数:

-(void)addItem:(NSDictionary *)item completion:(CompletionBlock)completion
{
// Insert the item into the Athlete table
[self.syncTable insert:item completion:^(NSDictionary *result, NSError *error)
{
[self logErrorIfNotNil:error];

// Let the caller know that we finished
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});
}];
}

现在一切都很好,该项目位于同步表中。问题是当我尝试与 Azure 移动服务同步时。这是我调用的syncData函数:

-(void)syncData:(CompletionBlock)completion
{
// push all changes in the sync context, then pull new data
[self.client.syncContext pushWithCompletion:^(NSError *error) {
[self logErrorIfNotNil:error];
[self pullData:completion];
}];
}

pushWithCompletion 给我带来错误:“提供的项目无效。”对于之后调用的 pullData 函数也是如此:

-(void)pullData:(CompletionBlock)completion
{
MSQuery *query = [self.syncTable query];

// Pulls data from the remote server into the local table.
// We're pulling all items and filtering in the view
// query ID is used for incremental sync
[self.syncTable pullWithQuery:query queryId:@"allAthletes" completion:^(NSError *error) {
[self logErrorIfNotNil:error];

// Let the caller know that we finished
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});

}];
}

我尝试直接插入 MSTable,效果很好。实际上,当我使用 MSSyncTable 时,我遇到了这个错误。尽管当我在数据库中手动插入数据并且同步上下文时,我可以获取数据并在 UITableView 中显示。

Here is my Athlete table期待看看你们对此有何看法。非常感谢!

感谢@phillipv,我刚刚编辑了我的问题。当我像我一样使用 NSDictionary 添加项目时,遇到了错误“提供的项目无效”。因此,我尝试添加一个项目,首先将其插入到我的 ManagedObjectContext 中,然后调用:

NSDictionary *dict = [MSCoreDataStore  tableItemFromManagedObject:newAthlete];

当我尝试同步时,我收到错误:“提供的项目没有有效的 ID。”

我感觉我正在经历一个圆圈..:S

最佳答案

@Charley14,您可以通过添加以下处理程序来解决该错误。

- (void)tableOperation:(nonnull MSTableOperation *)operation onComplete:(nonnull MSSyncItemBlock)completion
{
NSMutableDictionary *rwItem = [NSMutableDictionary dictionaryWithDictionary:operation.item];

// Temporary workaround
[rwItem removeObjectsForKeys:@[ @"relationship1", @"relationship2"]];

operation.item = rwItem;

[operation executeWithCompletion:completion];
}

tableOperation:onComplete: 处理程序只是删除与关系相对应的键。您必须将代码片段中的“relationship1”、“relationship2”替换为应用程序中实际关系的名称。一旦错误 (https://github.com/Azure/azure-mobile-services/issues/779) 被修复,这个解决方法就可以被删除。

关于ios - Azure 移动服务脱机数据同步 - 提供的项目无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com