iPhone应用程序中NSHost的替代品 [英] Alternatives to NSHost in iPhone app

查看:247
本文介绍了iPhone应用程序中NSHost的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此代码

    NSHost *host = [NSHost hostWithAddress:hostname];
if (host == nil) {
    host = [NSHost hostWithName:hostname];
    if (host == nil) {
        [self setMessage:@"Invalid IP address or hostname:"];
        return;
    }
}

来恢复网络应用的IP地址我正在努力,但我知道NSHost是一个私人API,将被拒绝。任何人都可以帮助我使用此代码生成相同的结果而不使用NSHost?我不确定从哪里开始。

to retrive my IP Address for a networking app I'm working on, however I'm aware that NSHost is a private API that will be rejected. Can anyone help me with working this code to produce the same results without using NSHost? I'm not really sure where to start.

编辑:

以下建议似乎该死的接近完美如下我已将此代码添加到我的应用程序中代替上面的代码

Following suggestions that seem damn near perfect below I've added this code into my app in the place of the code above

    Boolean result;
CFHostRef hostRef;
CFArrayRef addresses;
NSString *hostname = @"www.apple.com";
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
    result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
    if (result == TRUE) {
        addresses = CFHostGetAddressing(hostRef, &result);
    }
}
if (result == TRUE) {
    NSLog(@"Resolved");
} else {
    NSLog(@"Not resolved");
}

我删除了第4行(因为我已从其他地方获取此信息) )但我得到的错误是基于CFHostRef未声明的。我该如何解决?这似乎是我唯一的障碍,因为其他错误只是基于之后无法看到hostRef。
编辑:抓住我也得到kCFHostAddresses未声明。

I've removed the 4th line (as I have this information from elsewhere already) but I get errors being based around CFHostRef being undeclared. How would I resolve that? It seems to be my only big hurdle, as other errors are only based upon the lack of being able to see hostRef after that. Scratch that I also get kCFHostAddresses undeclared.

推荐答案

http://developer.apple.com/iphone/library/qa/qa2009/qa1652.html

通过开发人员支持系统得到了很好的答案,这非常有效。

Got a great little answer through the Developer Support system, this worked perfectly.

这篇关于iPhone应用程序中NSHost的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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