有点问题,我的数据加载是在
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
方法中,然后代码是这样子,按我的理解你的代码应该是实时监测网络,不管在任何界面,只要由无网络状态切换到有网,数据就应该开始加载了...- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GLobalRealReachability startNotifier]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:kRealReachabilityChangedNotification object:nil]; // 所有数据更新 [[NDNewsData sharedData] updateAd]; // 应用信息更新 [[NDNewsData sharedData] updateApp]; // 栏目数据更新 [[NDNewsData sharedData] updateSource]; return YES; }
-
(void)networkChanged:(NSNotification *)notification{
RealReachability * reachability = (RealReachability *)notification.object;
ReachabilityStatus status = [reachability currentReachabilityStatus];
if (status != RealStatusNotReachable)
{
// 所有数据更新
[[NDNewsData sharedData] updateAd];[[NDNewsData sharedData] updateApp];
[[NDNewsData sharedData] updateSource];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self name:kRealReachabilityChangedNotification object:nil];
}
-
这样写有什么毛病吗?为什么我无网状态下启动app,之后再打开网络还是没有加载呢?
截止20161118/15:15,这是一篇问题文章,当时用的是一位网友的类realReachAbility,结果最后没实现,还是用苹果官方的好一点,👇链接
2016/12/1,
关于实时网络监测问题,请点这👉设备网络监测及程序网络权限问题