Detect nearby mobile devices from an iOS app

ぃ、小莉子 提交于 2019-12-22 18:01:46

问题


Is it possible to create an iOS app which will scan for nearby mobile devices (eg. iPhone, Android, iPad etc), without needing to run any custom app on those nearby mobile devices?

I have tried using CoreBluetooth like so, running on my iPhone 6+:

[self.centralManager scanForPeripheralsWithServices:nil options:nil];

But the only nearby device it detects is my iMac, it will not detect my iPad Air 2, or my bluetooth earpiece.

Am I doing something wrong?


回答1:


Core Bluetooth works only with Bluetooth Low Energy (a.k.a. Bluetooth 4.0) devices, not the classic Bluetooth ones. In order to be discoverable, a device has to advertise one or more BLE services. You can implement CBPeripheralManager to do that and there's even sample code from Apple for the "scanner" and "peripheral" side. Note that this way you can also discover or be discovered by other mobile devices, like Android smartphones.

I don't know if it's possible to detect Hotspot or Handoff BLE services. Core Bluetooth does not allow you to access the "raw" Bluetooth Low Energy advertisement packets, so Apple probably does filter out some stuff.

If you want to detect only iOS devices (and no other BLE devices / accessories), you can also use Multipeer Connectivity framework. I personally find it a bit easier to use and it even provides a built-in "discovered devices" view. But you still have to run a custom app on both sides.




回答2:


If you are using Bluetooth low Energy, it will only detect the peripheral of BLE devices . However there is limitation of the range . By the documentation the BLE devices range is around 300 meter .You can get signal strength in CBCentralManager peripheral method :

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

Here RSSI is your signal strength .But the peripheral device has to be BLE enable i.e. bluetooth version 4.0 or above




回答3:


If you don't need to put whatever you're building on the App Store, you can jailbreak your iPhone and get direct access to the packets.

Bluetooth Companion, available in Cydia, will show you bluetooth packets on your phone. I'm not sure if that project's source is available, but you could look at other project like BTStack (there's a good Getting Started guide here).




回答4:


I will take the perspective of someone involved in embedded systems development. As was previously stated BLE only detects peripherals of other BLE devices, therefore I do not think Bluetooth technology is the best option for an app that detects nearby mobile devices.

Your app should consist of two detection features. One should have used Bluetooth to detect regular PC's and use GPS to detect other mobile devices, as it is the only other peripheral I believe is present in android and 4G ipad mini etc.

For your earpiece, if it is not detected then I do not know of any software solution that would modify hardware incompatibilities, so i would recommend you get an earpiece that is compatible with the bluetooth device.

Your problem is not a software one, it lies in the hardware limitations of the devices.



来源:https://stackoverflow.com/questions/27242392/detect-nearby-mobile-devices-from-an-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!