0

我試圖在應用程序處於後臺時連接到cB-OLP425 ble設備。我已經盡我所能在網絡上做到了。我使用IAR embededWorkbench將連接藍色的cb.demo.c中的廣告時間間隔設置爲20ms。在背景中連接到cB-OLP425 iphone應用程序

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用於在背景模式下的功能性。 不是音頻,因爲我聽說蘋果公司不會批准這個,如果它只是被添加到保持應用程序去睡覺。

有沒有人有任何建議或看到我需要改變/添加任何東西。我開始感到沮喪。

感謝您的任何和所有幫助

回答

0

對於後臺模式的中心,使用的plist關鍵「藍牙核心」是這樣的:

<key>UIBackgroundModes</key> 
<array> 
<string>bluetooth-central</string> 
</array> 

注意,在後臺模式中,您只能掃描與設備預定義的UUID服務。 此外,在後臺模式下獲取外設廣告時,您並不總是擁有廣告數據的「本地名稱」部分。

其實,在我的周圍BTLE的應用程序,在後臺模式,廣告不包括「本地名」。

我做的事,以確保連接我中心用適當的外設是我生成的UUID從我的中央,它保存在我的周圍,帶有某種自定義的配對過程的。 這樣,我的外設應用程序在後臺模式下發布了先前由我的中央服務器生成的服務UUID,即使沒有本地名稱,中央服務器也可以識別它。

+0

對不起,我花了這麼長時間來回應,但我正處在另一個項目的中間。你能告訴我在哪裏以及如何做這個定製配對而不用本地名字 – user1114881

相關問題