理想情况下,我希望在我的应用程序中有一个单一的可达性变量(如果这是可能的),但目前我的实现是按照下面的代码,并且在我的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) {...
我已经在多个视图上实现了这个(这似乎导致了问题.
多视图应用程序的建议方法是什么?
解决方法 [RKClIEnt sharedClIEnt]单例已经具有该属性(reachabilityObserver).随意使用那个.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的最佳方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)