简体   繁体   English

从BLE设备获取通知

[英]Get notification from a BLE device

I am working on a BLE (bluetooth LE) app that connects with a hardware device . 我正在研究与硬件设备连接的BLE (蓝牙LE)应用程序。 I am able to discover and connect to the device, read data from the device,write data to the device. 我能够发现并连接到设备,从设备读取数据,将数据写入设备。

What i couldn't find on the BLE docs in Apple , is how can you get a notification when you come near a device , when the app is close . 我在Apple的BLE文档中找不到的是,当您靠近设备,关闭应用程序时如何获得通知。

I know how to register to characteristic notification, but this notification happens only when app is in the background . 我知道如何注册characteristic通知,但是仅当应用程序在后台时才会发生此通知。

I know that iBeacon can detect a bluetooth while the app is closed, and send notification, but i would like to get notification when a device discover a certain BLE with a UUID . 我知道iBeacon可以在应用关闭时检测到蓝牙并发送通知,但是我想在设备发现具有UUID BLE时获得通知。

iBeacon,is using the BLE with UUID and major and minor fields,which i dont need/dont want . iBeacon正在将BLE与UUID以及major and minor字段major and minor字段一起使用,我不需要/不需要。 I would like just to register to notification from a certain UUID from a BLE. 我只想从BLE的某个UUID注册到通知。

I did this, without any respond : 我这样做了,没有任何回应:

 self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    [self initRegion];

- (void)initRegion
{
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"4AD3FADF-F179-4343-0000-000000000000"];
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"BLE-NAME"];
    [self.locationManager startMonitoringForRegion:self.beaconRegion];

}


- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
    NSLog(@"ENTER");

}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
    NSLog(@"EXIT");
}

While iBeacon and general BLE peripherals both use Bluetooth, they are handled differently within iOS. 尽管iBeacon和通用BLE外设都使用蓝牙,但它们在iOS中的处理方式有所不同。

iBeacons are supported by the CoreLocation framework (as per the code in your question), while BLE peripherals that implement the GATT profile are supported by the Core Bluetooth framework. iBeacons受到CoreLocation框架的支持(根据您问题中的代码),而实施GATT概要文件的BLE外围设备则由Core Bluetooth框架支持。

The Core Bluetooth Programming Guide describes how to discover and connect to a BLE peripheral. 核心蓝牙编程指南》介绍了如何发现并连接到BLE外设。 The guide also includes a section on background processing. 该指南还包括有关后台处理的部分。

Essentially you can issue a "connect" to your target peripheral and iOS will complete the connection when the peripheral is seen, even if your application is in the background - calling your delegate methods to advise you of the connection. 本质上,您可以向目标外围设备发出“连接”,并且即使看到您的应用程序在后台,iOS也会在看到外围设备时完成连接-调用委托方法来告知您该连接。

However, while many iBeacons can be configured with the same UUID, a peripheral's UUID is unique, so unless you have previously discovered the peripheral you probably won't be able to issue the connect. 但是,尽管可以使用相同的UUID配置许多iBeacon,但是外围设备的UUID是唯一的,因此,除非您先前已发现外围设备,否则您将可能无法发出连接。

You can scan for peripherals that are advertising specific services in the background and use this to discover and connect to peripherals 您可以在后台扫描发布特定服务的外围设备,并使用它来发现并连接到外围设备

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

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