我正在开发和应用程序,我需要在其中显示设备的蓝牙信息。我终于在蓝牙mac地址方面取得了一些成功,但无法获得设备名称。有没有办法通过一些公共api合法地获取设备名称?
NSString*btMacAddr = @"Bt ";
BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
const struct sockaddr_dl * dlAddr;
const uint8_t * base;
success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
if ( (cursor->ifa_addr->sa_family == AF_LINK)
&& (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == IFT_ETHER)
&& (strcmp(cursor->ifa_name, "en0") == 0)) {
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
if (dlAddr->sdl_alen == 6) {
//fprintf(stderr, ">>> WIFI MAC ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n", base[0], base[1], base[2], base[3], base[4], base[5]);
//fprintf(stderr, ">>> IPHONE BLUETOOTH MAC ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n", base[0], base[1], base[2], base[3], base[4], base[5]+1);
btMacAddr = [NSString stringWithFormat:@"Mac Address : %02x : %02x : %02x : %02x : %02x : %02x", base[0], base[1], base[2], base[3], base[4], base[5]+1];
} else {
fprintf(stderr, "ERROR - len is not 6");
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}