简体   繁体   English

CoreBluetooth - 背景模式下的iPhone广告

[英]CoreBluetooth - iPhone advertising in background mode

I am working on an iPhone and Mac OS X application, which allows you to lock and unlock your Mac via proximity. 我正在开发iPhone和Mac OS X应用程序,它允许您通过邻近区锁定和解锁Mac。 Means if you the signal strength is under a determined threshold or the connection gets lost it shall lock the mac. 意味着如果信号强度低于确定的阈值或连接丢失,则应锁定mac。

I am working with Apples CoreBluetooth framework for BTLE, using the iPhone as a peripheral and the Mac as a central. 我正在为BTLE使用Apples CoreBluetooth框架,使用iPhone作为外设,Mac作为中心。 So far so good. 到现在为止还挺好。 It also works very well but when I send the app to the background on the iPhone the advertising seems to change. 它也很好用但是当我将应用程序发送到iPhone的背景时,广告似乎发生了变化。 The iPhone still advertises but without the service profile and characteristics, I use in the app. iPhone仍在广告,但没有服务配置文件和特性,我在应用程序中使用。 Although this is not a problem when the iPhone is still in the range of the Mac, because it's still connected and the characteristics are not used in the central, it becomes a problem after moving the iPhone out of the range. 虽然当iPhone仍然在Mac的范围内时这不是问题,因为它仍然连接并且中央没有使用这些特性,所以在将iPhone移出范围后会出现问题。 As expected the Mac locks and starts discovering to reconnect the iPhone and unlock if succeeded. 正如预期的那样,Mac锁定并开始发现重新连接iPhone并解锁如果成功。

But in this discovery, I use the specified service profile and the characteristics to only get devices running my app and to identify the one for unlocking. 但在此发现中,我使用指定的服务配置文件和特性来仅运行运行我的应用程序的设备并识别用于解锁的设备。

I tried a workaround by discovering without a service profile and identifying the correct device via its UUID, which I saved when I started to use this iPhone for locking and unlocking. 我通过发现没有服务配置文件并通过其UUID识别正确的设备尝试了一种解决方法,当我开始使用此iPhone进行锁定和解锁时,我保存了该UUID。 This workaround also works in a small scope, because when I turn off the Bluetooth on the iPhone and turn it on again, it gets another UUID. 这种解决方法也适用于小范围,因为当我关闭iPhone上的蓝牙并再次打开它时,它会获得另一个UUID。 That's a constraint I could live with, but it also changes the UUID after a few hours and then the unlocking does not work. 这是我可以忍受的约束,但它也会在几个小时后更改UUID然后解锁不起作用。

Maybe someone already worked on an app like that and know how to fix such a problem? 也许有人已经在这样的应用程序上工作并知道如何解决这样的问题? Or you know a static value which I can use to identify the device? 或者你知道我可以用来识别设备的静态值吗?

So it seems, like usual, Apple has some weird and unique things going on in their framework. 所以看起来像往常一样,Apple在他们的框架中有一些奇怪而独特的东西。 When you advertise from an iOS device (such as your iPhone), there are two "storage areas" for the advertisements -- a normal one that any device that is scanning can see, and an "overflow" one that can only be seen by iOS devices that are specifically scanning for it. 当您从iOS设备(例如您的iPhone)做广告时,广告有两个“存储区域” - 正常扫描的任何设备都可以看到,以及“溢出”只能通过专门扫描它的iOS设备。 When your app advertises in the background, all services UUIDs that you advertise go into this overflow area unfortunately, so it looks like only other iOS devices can see it -- and not your Mac. 当您的应用程序在后台进行广告时,您发布的所有服务UUID很遗憾地进入此溢出区域,因此看起来只有其他iOS设备可以看到它 - 而不是您的Mac。 From the CBPeripheralManager docs : CBPeripheralManager文档

Any service universally unique identifiers (UUIDs) contained in the value of the CBAdvertisementDataServiceUUIDsKey key that do not fit in the allotted space are added to a special “overflow” area; CBAdvertisementDataServiceUUIDsKey键的值中包含的任何服务通用唯一标识符(UUID)不适合分配的空间,将添加到特殊的“溢出”区域; they can be discovered only by an iOS device that is explicitly scanning for them. 它们只能由显式扫描它们的iOS设备发现。 While your app is in the background, the local name is not advertised and all service UUIDs are placed in the overflow area. 当您的应用程序在后台时,不会公布本地名称,并且所有服务UUID都会放在溢出区域中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM