gpt4 book ai didi

ios - 使用 IP 地址连接到 Bonjour 服务

转载 作者:行者123 更新时间:2023-12-01 16:44:27 24 4
gpt4 key购买 nike

虽然我知道使用了 Bonjour,这样我们就不会弄乱 IPAddresses,但我需要编写一个可以“通过指定 IPAddress 手动添加新服务”的应用程序。

根据文档,可以通过按名称创建连接来做到这一点(其中名称现在是 ipaddress)[引用:https://developer.apple.com/library/ios/documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/ResolvingServices.html#//apple_ref/doc/uid/20001078-SW7 ]

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

switch (buttonIndex) {
case 0:
//Cancel
break;
case 1:
//OK
NSLog(@"%@",[[alertView textFieldAtIndex:0] text]);
[self searchServiceOfType:SERVICE_TYPE inDomain:@"" withName:[[alertView textFieldAtIndex:0] text]];
break;
default:
break;
}
}


-(void)searchServiceOfType:(NSString *)serviceType inDomain:(NSString *)domain withName:(NSString*)serviceName{

NSNetService *service;
service = [[NSNetService alloc] initWithDomain:domain
type:serviceType
name:serviceName];
[service setDelegate:self];
[service stop];
[service resolveWithTimeout:5.0];
}

该服务无法通过 errordict 解决
Printing description of errorDict:

{
NSNetServicesErrorCode = "-72004";
NSNetServicesErrorDomain = 10;
}

我错过了什么?

最佳答案

错误代码 -72004NSNetServicesBadArgumentError .
根据文档

- (id)initWithDomain:(NSString *)domain type:(NSString *)type name:(NSString *)name

你应该使用 @"local." (而不是 @"" )用于本地域。

关于ios - 使用 IP 地址连接到 Bonjour 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21136663/

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