我试图让我的代码更具功能性和反应性。我创建了一个这样的请求:
[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
。如何以反应方式做到这一点?
答案 0 :(得分: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 -----------------------------------------------
}];
}];