Hier ist die old Mobile Services page für die Behandlung von Konflikten mit dem iOS SDK. Das Setup für die Offline-Synchronisierung mit dem iOS-SDK hat sich seither nicht geändert.
1) Richten Sie eine MSSyncContextDelegate ein und übergeben Sie sie beim Erstellen an den MSSyncContext-Konstruktor. 2) Implementieren Sie tableOperation:(MSTableOperation *)operation onComplete:(MSSyncItemBlock)completion
in Ihrem Delegaten. Überprüfen Sie nach dem Ausführen des Vorgangs, ob der Fehlercode MSErrorPreconditionFailed
lautet, und entscheiden Sie anhand der Anforderungen Ihrer App, was Sie tun möchten.
- (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);
}
}];
}