Azre iOS 客户端 SDK 中的乐观并发

Optimistic concurrency in Azre iOS client SDK

我对 Azure 移动客户端 SDK 中的并发性有疑问。

windows 我发现 Conflict link 用于处理并发,但我找不到 iOS 客户端 SDK。

任何人都可以建议或帮助如何在 iOS 客户端 SDK 中处理并发。

这里是 old Mobile Services page 用于处理与 iOS SDK 的冲突。使用 iOS SDK 的离线同步设置从那时起就没有改变。

1) 设置一个MSSyncContextDelegate 并在创建它时将其传递给MSSyncContext 构造函数。 2) 在你的委托中实现 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);
        }
    }];
}