gpt4 book ai didi

iphone - ReachabilityWithAddress 给它一个 IP 地址时出错

转载 作者:行者123 更新时间:2023-12-03 20:52:44 25 4
gpt4 key购买 nike

嘿,我正在尝试查看是否可以连接到 IP 地址。

我的代码 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];

}
}

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

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

最佳答案

我在苹果提供的Reachability示例中测试了这个示例,希望你能明白。

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

关于iphone - ReachabilityWithAddress 给它一个 IP 地址时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9393645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com