2017-10-21 97 views
-1

我知道在iOS中,我們無法直接獲取設備的Mac ID。有沒有辦法,所以如果我有一個MAC ID,我可以將它轉換成CoreBluetooth給出的標識符。如何將已知的MAC地址轉換爲CBPheripheral標識符?

這是我的用例: 我有一個知道的Mac ID來自服務器。所以在可用設備列表中,我應該連接具有已知Mac ID的設備。任何解決方法?謝謝。

+0

不,你不能,除非你也許逆向工程「隨機」MAC到iOS使用的UUID。但是,如果您可以控制設備,則可以將其放入廣告數據或特徵值中,這有助於識別要連接的正確設備。 – Larme

回答

1

直接使用MAC地址不可能。但有辦法識別您的設備,發現UUID的服務。 有API稱爲

- (void)scanForPeripheralsWithServices:(NSArray<CBUUID *> *)serviceUUIDs 
           options:(NSDictionary<NSString *,id> *)options 

例如:

[self.centralManager 
scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:DEVICE_INFO_SERVICE_UUID]] 
         options:nil]; 

轉到最佳實踐https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/BestPracticesForInteractingWithARemotePeripheralDevice/BestPracticesForInteractingWithARemotePeripheralDevice.html

更多信息: https://medium.com/@yostane/getting-started-with-bluetooth-low-energy-on-ios-ada3090fc9cc