While I know Bonjour is used so that we don't get our hands messy with IPAddresses, but I need to write an app that can "manually add a new service by specifying the IPAddress".
According to the docs, one can do that by creating a connection by name (where the name is now the ipaddress) [Reference: 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];
}
The service doesn't resolve with errordict
Printing description of errorDict:
{
NSNetServicesErrorCode = "-72004";
NSNetServicesErrorDomain = 10;
}
What am I missing ?
Error code
-72004
isNSNetServicesBadArgumentError
. According to the documentation ofyou should use
@"local."
(and not@""
) for the local domain.