How to programmatically get the name of the Bluetooth adapter for iPhone in iOS

I am developing an application in which I need to show the information of a Bluetooth device. I finally made some progress regarding bluetooth mac address, but couldn't get the device name. Is there any way to legally get a device name through some public 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); } 
+4
source share
2 answers

Then it is not something like: [[UIDevice currentDevice] name];

This gives the name of the iOS device such as "Henriks iPhone"

+1
source

This is not indicated in the documentation, but in CBCentralManagerDelegate methods, such as centralManager: didDiscoverPeripheral: advertData: RSSI:, one of the delegate transfer options is CBPeripheral.

Interestingly, Apple does not list the official documentation for CBPeripheral, but if you look at the header file for CBPeripheral.h there seems to be a " _name " field that you could extract from there (for me, the compiler did not complain when I did " peripheral.name ", as if it had a specific property)

But again, to check my answer, I tried downloading the sample code of the Apple CoreBluetooth temperature sensor and running it with the command [centralManager scanForPeripheralsWithServices:nil options:nil]; "on my iPhone 4S without much success (generating the error" CoreBluetooth[WARNING] <CBConcreteCentralManager: 0x2087fc00> is not powered on ", even if Bluetooth is definitely set in the device’s settings).

Anyway, hopefully my tips can help you.

0
source

All Articles