【问题标题】:txtRecord is null when browsing for services (bonjour) using MYNetwork librariestxt 使用 MY Network 库浏览服务 (bonjour) 时记录为空
【发布时间】:2023-03-07 06:16:02
【问题描述】:

我目前正在使用 MYNetwork 库 Bonjour 类,但在发现 txt 记录时遇到了问题。当一个新服务出现时,它的 txt 记录每次都是空的。

在我的服务器端,我以这种方式设置 txt 记录:

self.server = [[MYBonjourRegistration alloc] initWithServiceType: @"_blipecho._tcp." port:9121];
[server setString:@"Cyprian" forTXTKey:@"Name"];
[server start];

然后在浏览器上我发现并记录数据:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
    {
        if ([keyPath isEqual:@"services"]) {

            NSSet *newServices = (NSSet*)[change objectForKey:@"new"];

            if(newServices){

                MYBonjourService *service;
                for (service in newServices){
                    textView.text  = [NSString stringWithFormat:@"%@\nNew user: %@ (%@)", textView.text, service.name, [service txtRecord]];

                }
            }
    }

我的 txtRecord 为空。

【问题讨论】:

    标签: objective-c cocoa networking bonjour


    【解决方案1】:

    好的,找到答案了。

    问题是新发现的服务还没有解决,因此没有数据。

    必须先解决服务。

    -(void)resolveService:(MYBonjourService*)service{
    
        service.addressLookup.continuous = YES;
        [service.addressLookup addObserver: self
                                forKeyPath: @"addresses"
                                   options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
                                   context: NULL];
        [service queryForRecord: kDNSServiceType_NULL];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      • 2016-08-16
      相关资源
      最近更新 更多