从iOS应用检测附近的移动设备 [英] Detect nearby mobile devices from an iOS app

查看:545
本文介绍了从iOS应用检测附近的移动设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建一个iOS应用程序,将附近的移动设备扫描(如iPhone,Android手机,iPad的等),而无需在这些附近的移动设备上运行的自定义应用程序?

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?

我一直在使用CoreBluetooth像这样尝试过,在我的iPhone上运行6 +

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

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

但它检测到的唯一附近的设备是我的iMac,它不会检测到我的iPad AIR 2,还是我的蓝牙耳机。

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

我是不是做错了什么?

推荐答案

核心蓝牙只能与蓝牙低功耗(又名蓝牙4.0)的设备,而不是经典蓝牙的。为了可发现,一个装置具有通告的一个或多个BLE服务。您可以实施 CBPeripheralManager 来做到这一点,甚至还有<一个href=\"https://developer.apple.com/library/ios/sample$c$c/BTLE_Transfer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012927\"相对=nofollow>样本code苹果,在扫描仪与外围的一面。请注意,这样你也可以发现或其他移动设备被发现,就像Android智能手机。

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.

我不知道是否有可能发现热点或切换BLE服务。核心蓝牙不允许你访问原始蓝牙低功耗广告数据包,因此苹果可能确实过滤掉一些东西。

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.

如果您想只检测iOS设备(并没有其他的BLE设备/配件),你也可以使用Multipeer连接框架。我个人觉得有点更容易使用,它甚至提供了一个内建的<一个href=\"https://developer.apple.com/Library/ios/documentation/MultipeerConnectivity/Reference/MCBrowserViewController_class/index.html\"相对=nofollow>发现设备的说法。但你仍然需要运行在两侧的自定义应用程序。

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.

这篇关于从iOS应用检测附近的移动设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆