我正在尝试在应用程序处于后台时连接到 cB-OLP425 ble 设备。我已经完成了我在网上可以找到的所有事情。我在使用 IAR embededWorkbench 连接蓝色的 cb.demo.c 时将广告间隔设置为 20 毫秒。
void gapSetAlwaysAdvertising(void)
{
uint8 advertising_enable = TRUE;
uint16 desired_min_advertising_interval = 20; **//I'M ASSUMING THIS IS 20ms changed it from 1600**
int16 desired_max_advertising_interval = 2500;
uint8 advertData[] = 0x02, //length of first data structure (2 bytes excluding length byte)
**//I'm thinking I need to change this to 0x05 which is 30 sec. am I correct**
GAP_ADTYPE_FLAGS, //AD Type = Flags
GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED
};
我已经通过重命名它的本地名称然后只允许连接到该名称来使其仅连接到一个特定模块。
我在某处读到这可能是一个问题,因为在后台这可能会被忽略?
我使用此代码查找模块
- (id)init
{
if ((self = [super init]))
{
self.characteristicsCBUUID = [NSMutableDictionary new];
self.myPeripherals = [NSMutableArray new];
manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
return self;
}
- (void)startScan
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:self.myPeripherals options:options];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, UUID: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.UUID, advertisementData);
NSDictionary *dataDict = [NSDictionary dictionaryWithObject:@"Specialname" forKey:@"kCBAdvDataLocalName" ];
if(![self.myPeripherals containsObject:peripheral])
[self.myPeripherals addObject:peripheral];
if ([advertisementData isEqualToDictionary:dataDict]) {
[manager retrievePeripherals:[NSArray arrayWithObject:(id) peripheral.UUID]];
}
}
我已将正确的信息添加到应用程序 Plist 中,以实现后台模式下的功能。不是音频,因为我听说如果只是添加它以防止应用程序进入睡眠状态,Apple 不会批准此操作。
有没有人有任何建议或看看我需要在哪里更改/添加任何东西。我开始感到沮丧。
感谢您的任何帮助