Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iPad应用程序中的网络连接警报视图_Iphone_Objective C - Fatal编程技术网

Iphone iPad应用程序中的网络连接警报视图

Iphone iPad应用程序中的网络连接警报视图,iphone,objective-c,Iphone,Objective C,如果没有网络,如何显示警报视图,因为我从服务器上的xml获取数据。您需要使用Apple可访问性 看看这个 将“Reachability.h”添加到UIViewController子类中,并在适用的情况下使用此代码 if (![[Reachability reachabilityForInternetConnection] isReachable]) { [[[[UIAlertView alloc] initWithTitle:@"No Internet connection!"

如果没有网络,如何显示警报视图,因为我从服务器上的xml获取数据。

您需要使用Apple可访问性

看看这个

将“Reachability.h”添加到UIViewController子类中,并在适用的情况下使用此代码

  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];
    }
}