2017-03-09 1 views
0

Ich habe eine Abfrage hinsichtlich der Parallelität in Azure Mobile Client SDK.Optimistische Nebenläufigkeit in Azre iOS-Client SDK

für Windows Ich fand Conflict link für die Behandlung von Nebenläufigkeit, aber ich konnte nicht das gleiche für iOS-Client SDK gefunden.

Kann mir bitte jemand empfehlen oder helfen, die Gleichzeitigkeit im iOS-Client-SDK zu behandeln.

Antwort

1

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); 
     } 
    }]; 
}