2016-08-22 3 views
0

블루투스 주변 장치의 광고 데이터를 중앙 관리자에서 편집해야합니다.광고 데이터를 편집하는 방법은 무엇입니까?

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { 

    NSLog(@"Connection successfull to peripheral: %@",peripheral); 
    peripheral.delegate = self; 
    [peripheral discoverServices:nil]; 
    //Do somenthing after successfull connection. 
} 

2.Discovering 서비스 :

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

    for (CBService *service in peripheral.services) { 
     NSLog(@"Discovering characteristics for service %@", service); 
     [peripheral discoverCharacteristics:nil forService:service]; 
    } 

} 
주변 장치 연결 1.After

: 내가 많이 노력

는 ..

다음 코드는 세부 사항을 제공합니다

3. 서비스에서 특성을 발견 :

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

    for (CBCharacteristic *characteristic in service.characteristics) { 
     if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"B0702880-A295-A8AB-F734-031A98A512DE"]]) { 
      [peripheral readValueForCharacteristic:characteristic]; 
      NSLog(@"Reading value for characteristic %@", characteristic); 
      [peripheral setNotifyValue:YES forCharacteristic:characteristic]; 
     } 
    } 
} 

4.Updating 알림 주 : 주변에

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


    NSLog(@"characteristic.properties--------------------->%lu",(unsigned long)characteristic.properties); 


    if (error) { 
     NSLog(@"Error changing notification state: %@",[error localizedDescription]); 
    } 
    // Notification has started 
    if (characteristic.isNotifying) { 
     NSLog(@"Notification began on %@", characteristic); 
    } 

    NSString* decodeString = @"teststring"; 
    NSData *encodeData = [decodeString dataUsingEncoding:NSUTF8StringEncoding]; 

    NSLog(@"to write----- %@",encodeData); 


    if ((characteristic.properties & CBCharacteristicPropertyWrite) || 
     (characteristic.properties & CBCharacteristicPropertyWriteWithoutResponse)) 
    { 
     [peripheral writeValue:encodeData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse]; 
    } 
    else 
    { 
     NSLog(@"Not permit to write"); 
    } 
} 

5.Update 쓰기 값 :

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

    if (error) { 
     NSLog(@"Error writing characteristic value: %@",[error localizedDescription]); 
    } 

    NSData *data = characteristic.value; 
    NSLog(@"FinalData:%@",data); 
} 

내가 IOS.Helps 새로운 사전에

감사 감사합니다입니다 ..

+0

광고 데이터에 무엇을하고 싶습니까? 표시 한 코드 중 귀하의 질문과 관련이없는 것 같습니다. 또한 주변 장치는 광고를 통해 중앙에서 어떻게 변경합니까? – Paulw11

+0

중앙에서 주변 기기로 광고를 수정한다고 가정합니다. 즉, 다음에 광고 데이터가 변경됩니다. 그래서 이것은 다른 프로필들처럼 간단한 서비스 나 특성입니다. 이제 너의 질문은 뭐니? 데이터를 장치로 전송 했습니까? 장치에서 데이터를 업데이트 했습니까? –

+0

내 중앙 장치에서 광고 데이터를 업데이트하고 싶습니다. 또한 주변 장치에 일부 값을 저장해야합니다. –

답변

1

일반적인 설정 방법은 없습니다. adv 중앙에서 주변 장치에 대한 데이터를 ertising. 이런 식으로하고 싶은 사람은 GATT 서비스를 통해 주변 장치에 기능을 구현해야합니다. 그렇지 않으면이 기능이 제품에 의해 제공됩니다.

광고는 링크 레이어 (LL) 기능이며 일반적으로 iOS에 노출되지 않습니다. BLE 용 iOS API는 GAP/GATT 수준입니다.