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

标签 ios azure azure-mobile-services

我对 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/

相关文章:

ios - 如何在 SwiftUI HStack 中隐藏剪辑 View

Azure VM 备份花费的时间比预期长

ios - 发布时 Azure iOS SDK 错误

azure - 我应该使用什么 Azure 移动服务 - TableController 或 API Controller ?

.net - Azure Net 后端发布,我必须在添加另一个迁移之前确实删除迁移吗?

ios - 用于在 xcode 中开发的应用程序的 64 位 Twitter 框架

ios - 此 bundle 无效 info.plist 中所需的 key 设备

iOS ScrollView 、容器 View - 自动布局问题

php - 是否有可能通过 Microsoft App 注册构建通用登录系统?

python - 使用 azure-eventhubs python 示例时出错