【问题标题】:Content editing input request as RACSignal内容编辑输入请求为 RACSignal
【发布时间】:2015-09-13 00:31:42
【问题描述】:

我正在尝试使我的代码更具功能性和反应性。我创建一个这样的请求:

[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
    options.networkAccessAllowed = YES;
    options.progressHandler = ^(double progress, BOOL *stop) {
        // update UI
    };

    [asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
        // subscriber send next/completed/error
    }];

    return [RACDisposable disposableWithBlock:^{
        // here I should kill request if still active
    }];
}];

要取消 iCloud 请求,我必须在 progressHandler 中设置 *stop = YES;。如何以被动的方式做到这一点?

【问题讨论】:

    标签: ios functional-programming reactive-cocoa cancellation photosframework


    【解决方案1】:

    我已经设法通过在块中捕获的NSMutableArray 解决了这个问题。

    [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        // -- Change ---------------------------------------------------
        NSMutableArray *flag = [NSMutableArray array];
        // -- Change End -----------------------------------------------
    
        PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
        options.networkAccessAllowed = YES;
        options.progressHandler = ^(double progress, BOOL *stop) {
    
            // -- Change ---------------------------------------------------
            if(flag.count > 0) {
                *stop = YES;
            } else {
                // update UI
            }
            // -- Change End -----------------------------------------------
         };
    
        [asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
            // subscriber send next/completed/error
        }];
    
        return [RACDisposable disposableWithBlock:^{
            // -- Change ---------------------------------------------------
            [flag addObject:@0];
            // -- Change End -----------------------------------------------
        }];
    }];
    

    【讨论】:

      猜你喜欢
      • 2015-09-12
      • 1970-01-01
      • 2016-04-25
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多