2014-09-30 6 views
0

Я использую Core Bluetooth для подключения двух устройств ios. Все работает идеально для ios 7, но для ios 8 нет. Устройство с ios 8 не отображается как периферийное устройство.Core bluetooth ios 8

Некоторый код:

_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; 

     [_peripheralManager startAdvertising:@{CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]}]; 

- (void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{ 

    if (error) { 
     [self cleanup]; 
     return; 
    } 

    for (CBService *service in peripheral.services) { 
     [peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]] forService:service]; 

    } 

} 

- (void) peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{ 


    if(error){ 
     [self cleanup]; 
     return; 
    } 

    for (CBCharacteristic *charactristic in service.characteristics) { 

     if ([charactristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) { 
      [peripheral setNotifyValue:YES forCharacteristic:charactristic]; 
     } 
    } 

} 

- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{ 

    if (error) { 
     return; 
    } 

    NSString *stringFromData = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]; 

    [peripheral setNotifyValue:NO forCharacteristic:characteristic]; 
    [_centralManager cancelPeripheralConnection:peripheral]; 

    [_data appendData:characteristic.value]; 

    NSDictionary *recievedData = [NSDictionary dictionaryWithObject:stringFromData forKey:@"receivedData"]; 

    [[NSNotificationCenter defaultCenter] 
    postNotificationName:DATA_FROM_PERIPHERAL_RECEIVED 
    object:self userInfo:recievedData]; 


    // } 

} 

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{ 

    if (![characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) { 
     return; 
    } 

    if (characteristic.isNotifying) { 
     NSLog(@"Notification began on %@", characteristic); 
    }else{ 
     [_centralManager cancelPeripheralConnection:peripheral]; 
    } 


} 
+0

Пожалуйста, уточните свой вопрос, что вы пытались, что вы подозреваете, и подобные части информации. – allprog

+0

Используя LigthBlue, другое устройство найдет его? – Larme

+0

Устройство на ios 8 не обнаружено LightBlue. Тот же случай, что и для моего приложения. – Natali

ответ

0

iOS 8.0 bluetooth peripheral manager giving no callback for addService - Этот вопрос мне помогает решить эту проблему. Просто нужно двигаться

[_peripheralManager startAdvertising:@{CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]}]; 

к -(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral методу:

-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{ 

    if (peripheral.state != CBPeripheralManagerStatePoweredOn) { 
     return; 
    } 

    if (peripheral.state == CBPeripheralManagerStatePoweredOn) { 

     [_peripheralManager startAdvertising:@{CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]}]; 

     self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID] properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable]; 
     CBMutableService *transferService = [[CBMutableService alloc]initWithType:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID] primary:YES]; 
     transferService.characteristics = @[_transferCharacteristic]; 
     [_peripheralManager addService:transferService]; 
    } 

} 

Теперь все отлично работает для ИОС 6,7,8.

Смежные вопросы