ReachabilityWithAddress错误,给它一个IP地址 [英] ReachabilityWithAddress error giving it an ip address

查看:107
本文介绍了ReachabilityWithAddress错误,给它一个IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我试图查看我是否可以连接到IP地址.

hey Im trying to see if I can connect to an IP address.

我的代码atm:

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

    }
}

有人可以告诉我如何使这项工作吗?

Can someone tell me plz how to make this work?

我不知道如何在此处插入IP地址...

I have no idea how to insert an ip address there...

推荐答案

我在苹果提供的可达性示例中测试了该示例,希望您能理解.

I tested this sample in Reachability sample provided by apple, hope you get the idea.

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

这篇关于ReachabilityWithAddress错误,给它一个IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆