Closed 983563622 closed 8 years ago
网络波动(并非切换网络方式),出现网络不可达,但是这是这一点不可达,未来的非常快的一个时间点恢复网络了,触发通知回调很慢(对于这一点的验证:我在网络不可达以后立马通过提供的block获取但网络状态是可达的) 代码如下:
@interface RRController ()
@property (weak, nonatomic) IBOutlet UILabel statusLabel; /< 网络状态视图 /
@end
@implementation RRController
(void)viewDidLoad { [super viewDidLoad];
[self setupUIForRR]; }
(void)dealloc { BKLog(@"");
[[NSNotificationCenter defaultCenter] removeObserver:self]; }
(IBAction)clickBntForRR:(id)sender { UIStoryboard main = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController detailController = [main instantiateViewControllerWithIdentifier:@"RRDetailController"];
if (detailController) { [self.navigationController pushViewController:detailController animated:YES]; } }
(void)networkChanged:(NSNotification )notification { RealReachability reachability = (RealReachability *)notification.object; ReachabilityStatus status = [reachability currentReachabilityStatus];
BKLog(@"status = %zd", status);
[self refreshStatusLabel:status]; }
(void)refreshNetworkStatus { [[RealReachability sharedInstance] reachabilityWithBlock:^(ReachabilityStatus status) { BKLog(@"status = %zd", status);
[self refreshStatusLabel:status];
}]; }
本来我为演示效果录的是gif动画,不知为何显示成静态图片了...如果需要查看,QQ:983563622,谢谢!
applicationDidBecomeActive 里不需要手动调用reachabilityWithBlock,框架里已经做了处理。我加你qq了,细聊哈
网络波动(并非切换网络方式),出现网络不可达,但是这是这一点不可达,未来的非常快的一个时间点恢复网络了,触发通知回调很慢(对于这一点的验证:我在网络不可达以后立马通过提供的block获取但网络状态是可达的) 代码如下:
import "RRController.h"
import "RealReachability.h"
@interface RRController ()
@property (weak, nonatomic) IBOutlet UILabel statusLabel; /< 网络状态视图 /
@end
@implementation RRController
pragma mark - life cycle
(void)viewDidLoad { [super viewDidLoad];
[self setupUIForRR]; }
(void)dealloc { BKLog(@"");
[[NSNotificationCenter defaultCenter] removeObserver:self]; }
pragma mark - event response
(IBAction)clickBntForRR:(id)sender { UIStoryboard main = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController detailController = [main instantiateViewControllerWithIdentifier:@"RRDetailController"];
if (detailController) { [self.navigationController pushViewController:detailController animated:YES]; } }
pragma mark - callback
(void)networkChanged:(NSNotification )notification { RealReachability reachability = (RealReachability *)notification.object; ReachabilityStatus status = [reachability currentReachabilityStatus];
BKLog(@"status = %zd", status);
[self refreshStatusLabel:status]; }
pragma mark - private method
(void)refreshNetworkStatus { [[RealReachability sharedInstance] reachabilityWithBlock:^(ReachabilityStatus status) { BKLog(@"status = %zd", status);
}]; }
@end