大佬教程收集整理的这篇文章主要介绍了xcode – 在RestKit中实现RKReachabilityObserver的最佳方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
理想情况下,我希望在我的应用程序中有一个单一的可达性变量(如果这是可能的),但目前我的实现是按照下面的代码,并且在我的4个选项卡上复制时效果不佳.
View.h
@property (nonatomic,retain) RKReachabilityObserver *observer;
View.m
@interface AppViewController() { RKReachabilityObserver *_observer; } @property (nonatomiC) BOOL networkIsAvailable; @synthesize observer = _observer; -(id)initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { self.observer = [[RKReachabilityObserver alloc] initWithHost:@"mydomain"]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(reachabilityChanged:) name:rKReachabilityDidChangeNotification object:_observer]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // determine network availability if (! [_observer isReachabilityDetermined]) { _networkIsAvailable = YES; } else { _networkIsAvailable = NO; } _text.returnKeyType = UIReturnKeyDone; _text.delegate = self; } - (void)reachabilityChanged:(Nsnotification *)notification { RKReachabilityObserver* observer = (RKReachabilityObserver *) [notification object]; if ([observer isNetworkReachable]) { if ([observer isConnectionrequired]) { _networkIsAvailable = YES; NSLog(@"Reachable"); return; } } else { _networkIsAvailable = NO; NSLog(@"Not reachable"); } }
然后在我看来,我只是做….
if (_networkIsAvailable == YES) {...
我已经在多个视图上实现了这个(这似乎导致了问题.
多视图应用程序的建议方法是什么?
if ([[[RKClient sharedClient] reachabilityObserver] isReachabilityDetermined] && [[RKClient sharedClient] isNetworkReachable]) { .... }
您还可以订阅RKReachabilityObserver通知(如果您希望在可达性状态更改时执行任何操作)
[[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(reachabilityStatusChanged:) name:rKReachabilityDidChangeNotification object:nil];
以上是大佬教程为你收集整理的xcode – 在RestKit中实现RKReachabilityObserver的最佳方法全部内容,希望文章能够帮你解决xcode – 在RestKit中实现RKReachabilityObserver的最佳方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。