对于失败的信号没有处理
- (void)setup {
//定位
_locationManager = [[DellocCLLocationManager alloc] init];
_geoCoder = [[CLGeocoder alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = 1.0;
_currentLocation=[[CLLocation alloc]initWithLatitude:31.232032 longitude:121.476173];
@weakify(self);
[[[[[self authorizedSignal] filter:^BOOL(id value) {
return [value boolValue];
}] flattenMap:^RACStream *(id value) {
@strongify(self);
return [[[[[[self rac_signalForSelector:@selector(locationManager:didUpdateLocations:) fromProtocol:@protocol(CLLocationManagerDelegate)] map:^id(id value) {
CLLocation *firstLocation= [value[1] firstObject];
CLLocationCoordinate2D coordinate = [JZLocationConverter wgs84ToGcj02:firstLocation.coordinate];
CLLocation *correctLocation=[[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
return correctLocation;
}] merge:[[self rac_signalForSelector:@selector(locationManager:didFailWithError:) fromProtocol:@protocol(CLLocationManagerDelegate)] map:^id(id value) {
return [RACSignal error:value[1]];
}]] take:1] initially:^{
@strongify(self);
[self.locationManager startUpdatingLocation];
}] finally:^{
@strongify(self);
[self.locationManager stopUpdatingLocation];
}];
}] flattenMap:^RACStream *(id value) {
if (![value isKindOfClass:[CLLocation class]]) {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@"定位失败"];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
}];
}];
}
CLLocation *firstLocation= value;
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
@strongify(self);
[self.geoCoder reverseGeocodeLocation:firstLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (error) {
[subscriber sendNext:error];
}else{
[subscriber sendNext:[placemarks firstObject]];
[subscriber sendCompleted];
}
}];
return [RACDisposable disposableWithBlock:^{
}];
}];
}] subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
}