Iphone iPad应用程序中的网络连接警报视图
如果没有网络,如何显示警报视图,因为我从服务器上的xml获取数据。您需要使用Apple可访问性 看看这个 将“Reachability.h”添加到UIViewController子类中,并在适用的情况下使用此代码Iphone iPad应用程序中的网络连接警报视图,iphone,objective-c,Iphone,Objective C,如果没有网络,如何显示警报视图,因为我从服务器上的xml获取数据。您需要使用Apple可访问性 看看这个 将“Reachability.h”添加到UIViewController子类中,并在适用的情况下使用此代码 if (![[Reachability reachabilityForInternetConnection] isReachable]) { [[[[UIAlertView alloc] initWithTitle:@"No Internet connection!"
if (![[Reachability reachabilityForInternetConnection] isReachable]) {
[[[[UIAlertView alloc] initWithTitle:@"No Internet connection!"
message:@"You have no active internet connection. Please enable wi-fi and re-launch the app."
delegate:nil
cancelButtonTitle:@"Close"
otherButtonTitles:nil, nil] autorelease] show];
return;
}
我在检查网络可用性时遇到了类似的问题。 苹果的可达性代码将在iOS5 ARC特性下抛出错误 最后,我在gitHub中找到了这个工作项目 它很容易实现,并且在网站上给出了说明 比尔,
正如大家所说,您需要使用Reachability.h和Reachability.m。 但没有人提到通知的正确变体: 首先,您需要向类中添加变量。最好在
.m
文件中将其声明为私有:
@implementation YourClass
Reachability* reachability;
@end
然后,您必须创建新的可达性,并将观察者(自身)添加到通知中心:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showInetConnection)
name:kReachabilityChangedNotification
object:nil];
reachability = [[Reachability reachabilityForInternetConnection] retain];
[reachability startNotifier];
从apple看可达性类
-(void)showInetConnection
{
if ([reachability currentReachabilityStatus]==NotReachable) {
UIAlertView* view = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"There are no inet connection"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[view show];
[view release];
}
}