第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

對(duì)于失敗的信號(hào)沒(méi)有處理

- (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);

? ? }];

}

http://img1.sycdn.imooc.com//58c351670001a59f08530468.jpg



正在回答

4 回答

這里判斷不是 CLLocation 類型來(lái)判斷的, 可以使用 sendError 。我也忘了錄課時(shí)候?yàn)槭裁词褂胹endnext了。

0 回復(fù) 有任何疑惑可以回復(fù)我~

我這邊這么處理的..

??RACSignal *locationSignal = [[[[self authorizedSignal] filter:^BOOL(id? _Nullable value) {

? ? ? ? //判斷是否有權(quán)限

? ? ? ? return [value boolValue];

? ? }] flattenMap:^__kindof RACSignal * _Nullable(id? _Nullable value){

? ? ? ? //監(jiān)聽(tīng)地址刷新的狀態(tài)

? ? ? ? return [[[[[[self rac_signalForSelector:@selector(locationManager:didUpdateLocations:) fromProtocol:@protocol(CLLocationManagerDelegate)] map:^id _Nullable(id? _Nullable value) {

? ? ? ? ? ? return value[1];

? ? ? ? ? ? //混合錯(cuò)誤監(jiān)聽(tīng)

? ? ? ? }] merge:[[self rac_signalForSelector:@selector(locationManager:didFailWithError:) fromProtocol:@protocol(CLLocationManagerDelegate)] map:^id _Nullable(id? _Nullable value) {

? ? ? ? ? ? //返回錯(cuò)誤

? ? ? ? ? ? return [RACSignal error:value[1]];

? ? ? ? }]] take:1] initially:^{

? ? ? ? ? ? //initially 在所有之前開(kāi)始

? ? ? ? ? ? [self.manager startUpdatingLocation];

? ? ? ? }] finally:^{

? ? ? ? ? ? //finally 處理完之后

? ? ? ? ? ? [self.manager stopUpdatingLocation];

? ? ? ? }];

? ? }] flattenMap:^__kindof RACSignal * _Nullable(id? _Nullable value) {

?? ? ? ?

? ? ? ? return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>? _Nonnull subscriber) {

? ? ? ? ? ? if ([[value class] isSubclassOfClass:[RACErrorSignal class]]) {

? ? ? ? ? ? ? ? [subscriber sendError:value];

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? CLLocation *location = [value firstObject];

? ? ? ? ? ? ? ? [self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

? ? ? ? ? ? ? ? ? ? if (error) {

? ? ? ? ? ? ? ? ? ? ? ? [subscriber sendError:error];

? ? ? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? ? ? [subscriber sendNext:[placemarks firstObject]];

? ? ? ? ? ? ? ? ? ? ? ? [subscriber sendCompleted];

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }];

? ? ? ? ? ? }

? ? ? ? ? ? return [RACDisposable disposableWithBlock:^{

? ? ? ? ? ? }];

? ? ? ? }];

? ? }];


0 回復(fù) 有任何疑惑可以回復(fù)我~

和你不太一樣的地方就是我把你手動(dòng)該的 RACStream 的返回值改成了 id 下面貼上我的代碼吧:

-?(void)setup?{
????//定位
????_locationManager?=?[[CLLocationManager?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:^id?(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?=?firstLocation.coordinate;
????????????CLLocation?*correctLocation=[[CLLocation?alloc]initWithLatitude:coordinate.latitude?longitude:coordinate.longitude];
????????????return?@(22);
????????}]?merge:[[self?rac_signalForSelector:@selector(locationManager:didFailWithError:)?fromProtocol:@protocol(CLLocationManagerDelegate)]?map:^id(id?value)?{
????????????return?[RACSignal?error:value[1]];
????????}]]?take:1]?initially:^{
????????????@strongify(self);
????????????[_locationManager?startUpdatingLocation];
????????}]?finally:^{
????????????@strongify(self);
????????????[_locationManager?stopUpdatingLocation];
????????}];
????}]?flattenMap:^id?(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);
????????????[_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);
????}];
}


0 回復(fù) 有任何疑惑可以回復(fù)我~

我用你的代碼實(shí)驗(yàn)一下...走了啊..我把

locationManager:didUpdateLocations:

這個(gè)方法的時(shí)候你 return 的

correctLocation

這個(gè)位置的值直接用 @222 這么一個(gè) NSNumber 類型替換了, 運(yùn)行的時(shí)候走了定位失敗...

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
iOS之ReactiveCocoa框架
  • 參與學(xué)習(xí)       6490    人
  • 解答問(wèn)題       10    個(gè)

本iOS視頻教程讓你快速上手ReactiveCocoa框架,達(dá)到靈活運(yùn)用

進(jìn)入課程

對(duì)于失敗的信號(hào)沒(méi)有處理

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)