【发布时间】:2013-03-17 19:58:51
【问题描述】:
我想通过应用程序简单地使用可达性来检查互联网连接的可用性。当互联网连接丢失时,我想显示一个半透明的自定义视图(叠加层)(仍然可以看到后面显示的视图),其中包含一些文本,例如 ...Checking for Internet Connection。
这看起来很简单,但我无法按预期工作。
我已阅读有关可达性的苹果文档,并且日志似乎工作正常。我想确认我是否按预期正确设置了此设置,以及如何在连接恢复时生成透明视图/隐藏视图。
应用代理:
我打电话给[self setupReachability];
那我有这些方法:
- (void)setupReachability {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:ReachabilityChangedNotification object:nil];
self.internetReach = [Reachability reachabilityForInternetConnection];
[self.internetReach startNotifier];
[self checkConnection:internetReach];
}
#pragma mark -
#pragma mark - Reachability
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note {
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self checkConnection: curReach];
}
-(void)checkConnection: (Reachability*) curReach {
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(@"inernet reach - not reachable");
}
}
我知道我可以创建这样的模式视图:
UIView *modalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
modalView.opaque = NO;
modalView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
UILabel *label = [[UILabel alloc] init];
label.text = @"Modal View";
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
[label sizeToFit];
[modalView addSubview:label];
但我不确定如何将其添加到屏幕上当前显示的任何视图控制器/导航控制器?
编辑: 发生错误:
【问题讨论】:
标签: ios ios5 uiview reachability