0
目前我創建一個內部信號來呼叫[Watchtower reportToServerWithBeaconRegionArraySignal:]
,因爲這樣我只能通過next
s,並捕獲完成和錯誤信號,我不想傳播,因爲我想保留從[self rangedBeaconsSignal]
進一步信號的訂閱。我試過使用catch:
(並且從那裏提供的塊返回[RACSignal empty]
),但是它只捕獲錯誤,而不是完成。但是我沒有看到它:我嘗試使用catch:
(並從那裏提供的塊返回[RACSignal empty]
),但只捕獲錯誤,不完成。有沒有更好的方法來捕獲錯誤和完成?
(?附註:我能不能檢查我使用[disposable dispose]
也是正確這裏可能是多餘的):
[[[self rangedBeaconsSignal] flattenMap:^RACStream * (CLBeaconRegion *region) {
return [RACSignal createSignal:^RACDisposable * (id <RACSubscriber> subscriber) {
RACDisposable *disposable= [RACDisposable new];
[[Watchtower reportToServerWithBeaconRegionArraySignal:@[region] fromBackground:NO]
subscribeNext:^(id x) {
[subscriber sendNext:x];
} error:^(NSError *error) {
[disposable dispose];
} completed:^{
[disposable dispose];
}];
return disposable;
}];
}] subscribeNext:^(id x) {
NSLog(@"Sent beacon to server");
} error:^(NSError *error) {
// ideally errors might reach here, but I don't want to unsubscribe, so I'm ignoring them for now.
} completed:^{
}];