1

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

[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 请求,我必须*stop = YES;progressHandler. 如何以反应的方式做到这一点?

4

1 回答 1

0

我已经设法通过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-06-28T10:06:47.933 回答