Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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 为其提供ip地址时出现ReachabilityWithAddress错误_Iphone_Ip Address_Connectivity - Fatal编程技术网

Iphone 为其提供ip地址时出现ReachabilityWithAddress错误

Iphone 为其提供ip地址时出现ReachabilityWithAddress错误,iphone,ip-address,connectivity,Iphone,Ip Address,Connectivity,嘿,我想看看我是否可以连接到一个IP地址 我的自动取款机代码: #import "ViewController.h" #import "SystemConfiguration/SystemConfiguration.h" @implementation ViewController struct sockaddr_in ; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading t

嘿,我想看看我是否可以连接到一个IP地址

我的自动取款机代码:

#import "ViewController.h"
#import "SystemConfiguration/SystemConfiguration.h"

@implementation ViewController
struct sockaddr_in ;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

Reachability *d = [Reachability reachabilityWithAddress:const struct sockaddr_in     ???????];
NetworkStatus internetStatus = [d currentReachabilityStatus];
//NetworkStatus internetStatus = [d currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus!= ReachableViaWWAN)){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No internet" message:@"No internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
   [alert release];
}
else {
    UIAlertView *notify = [[UIAlertView alloc] initWithTitle:@"Internet" message:@"There is internet!(not)" delegate:self cancelButtonTitle:@"funny" otherButtonTitles:nil];
    [notify show];
    [notify release];  

    }
}
有人能告诉我怎么做吗


我不知道如何在那里插入ip地址

我在苹果提供的可达性样本中测试了这个样本,希望你能理解

//Change the host name here to change the server your monitoring
remoteHostLabel.text = [NSString stringWithFormat: @"Remote Host: %@", @"www.apple.com"];
//commented this line in the applicationDidFinishLaunching of ReachabilityAppDelegate.m file
//hostReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
 struct sockaddr_in tAddr;
tAddr.sin_len = 16;
tAddr.sin_port = htons(80);
struct in_addr  address;
address.s_addr = htons(0x4a7de048);
tAddr.sin_family = AF_INET;
 //http://74.125.224.72/ this ip adress is for google
 //4a7de048 **updated** Hexadecimal representation of IP address 74.125.224.72

hostReach = [[Reachability reachabilityWithAddress:&tAddr] retain];

我在苹果提供的可达性样本中测试了这个样本,希望你能理解

//Change the host name here to change the server your monitoring
remoteHostLabel.text = [NSString stringWithFormat: @"Remote Host: %@", @"www.apple.com"];
//commented this line in the applicationDidFinishLaunching of ReachabilityAppDelegate.m file
//hostReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
 struct sockaddr_in tAddr;
tAddr.sin_len = 16;
tAddr.sin_port = htons(80);
struct in_addr  address;
address.s_addr = htons(0x4a7de048);
tAddr.sin_family = AF_INET;
 //http://74.125.224.72/ this ip adress is for google
 //4a7de048 **updated** Hexadecimal representation of IP address 74.125.224.72

hostReach = [[Reachability reachabilityWithAddress:&tAddr] retain];

此代码适用于我:

    struct sockaddr_in localWifiAddress;
    bzero(&localWifiAddress, sizeof(localWifiAddress));
    localWifiAddress.sin_len = sizeof(localWifiAddress);
    localWifiAddress.sin_family = AF_INET;
    localWifiAddress.sin_addr.s_addr = htonl(0x0A0A0A7B); // hex representation of your local IP

    Reachability *reachability = [Reachability reachabilityWithAddress:&localWifiAddress];    
    reachability.key = kLocalWiFiConnection;
    return [reachability isReachable];

此代码适用于我:

    struct sockaddr_in localWifiAddress;
    bzero(&localWifiAddress, sizeof(localWifiAddress));
    localWifiAddress.sin_len = sizeof(localWifiAddress);
    localWifiAddress.sin_family = AF_INET;
    localWifiAddress.sin_addr.s_addr = htonl(0x0A0A0A7B); // hex representation of your local IP

    Reachability *reachability = [Reachability reachabilityWithAddress:&localWifiAddress];    
    reachability.key = kLocalWiFiConnection;
    return [reachability isReachable];

你为什么不试着读一下苹果公司提供的例子呢?是的,我已经读过了,但没有完全理解,因为这是他们说的那句话;+可达性*可达性WithAddress:const struct sockaddr_in*主机地址;我需要填写主机地址,但我现在的问题是如何,你有什么建议?就像我说的-检查苹果提供的示例。它的存在是有原因的-它向你展示了一个完整的例子,如何做到这一点。你为什么不试着读一下苹果公司提供的例子呢?是的,我已经读过了,但没有完全理解,因为这是他们说的那句话;+可达性*可达性WithAddress:const struct sockaddr_in*主机地址;我需要填写主机地址,但我现在的问题是如何,你有什么建议?就像我说的-检查苹果提供的示例。它的存在是有原因的-它向你展示了一个完整的例子,如何做到这一点。非常感谢!这很有效。现在我看到他们把我如何写结构omg的解释放在哪里了。非常感谢!这很有效。现在我看到他们把我如何编写结构omg的解释放在哪里了。。