0

Is there a willing soul who could kindly help me with this problem?

This is my scenario:

I need to upload form attachments to the server. So here are the steps:

  1. Retrieve attachment headers from server using Web service.

  2. Match the attachment header with local attachments.

  3. Upload attachments to server.

The Problem:

Using RACSignal I can successfully obtain the attachment headers but when it's time to upload the attachments using NSArray the inner RACSignal of the UploadFormItemAttachments method will not execute.

Additional Information:

This is the code snippet that shows how the RACSignals are handled. BatchSignal is never executed!:

[[[self getFormItemAttachmentHeaders:listName
                          topListItemID:form.topListItemID
                                  form:form
     ] map:^id(NSMutableArray* value) {
        NSArray* attachmentHeaders = [value copy];

        // the code of uploadFormItemAttachments is called but the inner signal does not execute. Why?
        return [self uploadFormItemAttachments:pendingAttachments
                                        attachmentHeaders:attachmentHeaders
                                                     form:form];
        }
      ] subscribeNext:^(id value) {
          // I was expecting the completion result form uploadFormItemAttachments here.
        }
     ];

This the method that iterates over the attachments array and uploads it to the server:

- (RACSignal *)uploadFormItemAttachments:(NSArray*)pendingAttachments attachmentHeaders:(NSArray*)attachmentHeaders form:(SEFSManagedForm*)form
{

  RACSignal* batchSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [attachmentHeaders enumerateObjectsUsingBlock:^(SEFSFormItemAttachmentHeader* attachmentHeader, NSUInteger idx, BOOL *stop)
     {
       // Look for the local attachment using attachment header from server

       NSPredicate* predicate = [NSPredicate predicateWithFormat:@"identifier = %@", attachmentHeader.document];
       NSArray* foundAttachment = [pendingAttachments filteredArrayUsingPredicate:predicate];

       SEFSManagedAttachment* fullAttachment = foundAttachment[0];

       RACSignal* uploadFormItemAttachmentSignal = [[self uploadFormItemAttachment:fullAttachment
                                                                  attachmentHeader:attachmentHeader                                                            ] map:^id(NSNumber* value) {
         NSMutableArray* valuesArray = [NSMutableArray array];
         [valuesArray addObject:value];
         [valuesArray addObject:attachmentHeader.document];
         RACTuple* tuple = [RACTuple tupleWithObjectsFromArray:valuesArray
                                            convertNullsToNils:YES];
         return tuple;
       }];


       [subscriber sendNext:uploadFormItemAttachmentSignal];
     }];

    [subscriber sendCompleted];
    return nil;
  }];

  return [batchSignal flatten:2];
}
4

1 に答える 1

0

uploadFormItemAttachments返品のため、代わりにRACSignal使用する必要がありますflattenMapmap

于 2016-11-13T05:17:57.477 に答える