在iOS上注册Airplay接收器后,它无法连接

时间:2018-01-09 16:26:13

标签: ios connection airplay mirroring

在iOS上成功注册Airplay服务后,我可以在控制中心的Airplay接收器列表中看到它。单击它时,它会尝试连接,但会以错误警报结束(连接到" myDevice"不可能)。

我使用dns-sd库中的DNSServiceRegister命令,我也发送了一个TXTRecord。

TXTRecordRef txtRecord;
TXTRecordCreate(&txtRecord, 0, NULL);
TXTRecordSetValue(&txtRecord, "deviceid", strlen("E4:83:E5:BE:2C:E6"), "E4:83:E5:BE:2C:E6");
TXTRecordSetValue(&txtRecord, "features", strlen("0x5A7FFFF7,0x1E"), "0x5A7FFFF7,0x1E");
TXTRecordSetValue(&txtRecord, "flags", strlen("0x4"), "0x4");
TXTRecordSetValue(&txtRecord, "model", strlen("AppleTV3,2"), "AppleTV3,2");
TXTRecordSetValue(&txtRecord, "pk", strlen("ef9b9591269732952ae02e43d9a856fd58a5bd53f845978a8e08363897abb955"),"ef9b9591269732952ae02e43d9a856fd58a5bd53f845978a8e08363897abb955");
TXTRecordSetValue(&txtRecord, "pi", strlen("5e66cf9b-0a39-4e0c-9d32-081a8ce63231"),"5e66cf9b-0a39-4e0c-9d32-081a8ce63231");
TXTRecordSetValue(&txtRecord, "srcvers", strlen("220.68"), "220.68");
TXTRecordSetValue(&txtRecord, "vv", strlen("2"), "2");

...

DNSServiceRegister(&dnssd_service, 0, 0, [serviceString UTF8String], "_airplay._tcp", "local.", "myname.local", port, TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord), NULL, NULL);

任何想法为什么只有将服务添加到列表中才有效,但iOS设备无法连接到它?

1 个答案:

答案 0 :(得分:0)

我在

之后添加了一些命令
DNSServiceRegister(...);

我补充说:

/* Converts ascii text to in_addr struct.  NULL is returned if the
 address can not be found. */
struct in_addr *atoaddr(char *address) {
    struct hostent *host;
    static struct in_addr saddr;

    /* First try it as aaa.bbb.ccc.ddd. */
    saddr.s_addr = inet_addr(address);
    if (saddr.s_addr != -1) {
        return &saddr;
    }
    host = gethostbyname(address);
    if (host != NULL) {
        return (struct in_addr *) *host->h_addr_list;
    }
    return NULL;
}
void mycallback(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, void *context) {
    printf("Callback hit\n");
}

...

DNSRecordRef recordRef = malloc(sizeof(DNSRecordRef));
DNSServiceRef mainRef;
DNSServiceErrorType error = DNSServiceCreateConnection(&mainRef);
if (error) {
    printf("DNSServiceCreateConnection failed\n");
    exit(1);
}

DNSServiceRef registerServiceRef = mainRef;
DNSServiceErrorType errE = DNSServiceRegisterRecord( registerServiceRef, &recordRef, kDNSServiceFlagsShared, 0, "myname.local", kDNSServiceType_A, kDNSServiceClass_IN, sizeof(addr), addr, 0, mycallback, NULL);

也许这有助于某人。