This seems to work:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = nil;
RACSignal *buttonSignal = [self.stepperButton rac_signalForControlEvents:UIControlEventTouchUpInside];
RACSignal *getSignal = [buttonSignal map:^id(UIButton *button) {
return [[manager rac_GET:@"https://farm3.staticflickr.com/2815/13668440264_e6403b3100_o_d.jpg" parameters:nil] catch:^RACSignal *(NSError *error) {
NSLog(@"catch %@",error);
return [RACSignal empty];
}];
}];
RACSignal *latestSignal = [getSignal switchToLatest];
[latestSignal subscribeNext:^(NSData *data) {
NSLog(@"dowloaded %d bytes",data.length);
}];
Thanks Stackoverflow similar questions! Powerful stuff.
The catch should be on the rac_GET. Before I had been trying to do things with catch but on the buttonSignal
pipe.
And the reason x
was always null
was because I did not have a serializer set up on the manager
.
I thought about deleting this question, but maybe there are people that still have remarks on the solution?