我对 Azure 移动客户端 SDK 中的并发性有疑问。
对于 Windows,我发现 Conflict link用于处理并发,但我找不到适用于 iOS 客户端 SDK 的相同内容。
任何人都可以建议或帮助如何处理 iOS 客户端 SDK 中的并发。
最佳答案
这是 old Mobile Services page用于处理与 iOS SDK 的冲突。从那时起,与 iOS SDK 离线同步的设置就没有改变。
1) 设置一个 MSSyncContextDelegate并在创建它时将其传递给 MSSyncContext 构造函数。
2) 在委托(delegate)中实现 tableOperation:(MSTableOperation *)operation onComplete:(MSSyncItemBlock)completion
。执行该操作后,检查是否有 MSErrorPreconditionFailed
错误代码,并根据应用的需要决定从那里做什么。
- (void)tableOperation:(MSTableOperation *)operation onComplete:(MSSyncItemBlock)completion
{
[operation executeWithCompletion:^(NSDictionary *item, NSError *error) {
NSDictionary *serverItem = [error.userInfo objectForKey:MSErrorServerItemKey];
if (error.code == MSErrorPreconditionFailed) {
QSUIAlertViewWithBlock *alert = [[QSUIAlertViewWithBlock alloc] initWithCallback:^(NSInteger buttonIndex) {
if (buttonIndex == 1) { // Client
NSMutableDictionary *adjustedItem = [operation.item mutableCopy];
[adjustedItem setValue:[serverItem objectForKey:MSSystemColumnVersion] forKey:MSSystemColumnVersion];
operation.item = adjustedItem;
[self doOperation:operation complete:completion];
return;
} else if (buttonIndex == 2) { // Server
NSDictionary *serverItem = [error.userInfo objectForKey:MSErrorServerItemKey];
completion(serverItem, nil);
} else { // Cancel
[operation cancelPush];
completion(nil, error);
}
}];
NSString *message = [NSString stringWithFormat:@"Client value: %@\nServer value: %@", operation.item[@"text"], serverItem[@"text"]];
[alert showAlertWithTitle:@"Server Conflict"
message:message
cancelButtonTitle:@"Cancel"
otherButtonTitles:[NSArray arrayWithObjects:@"Use Client", @"Use Server", nil]];
} else {
completion(item, error);
}
}];
}
关于ios - Azre iOS 客户端 SDK 中的乐观并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42687517/