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に新しい事前に
おかげで高く評価されています..
広告データに何をしたいですか?あなたが表示したコードのどれもあなたの質問に関連していないようです。また、周辺機器は広告をどのように中央から変更するのでしょうか? – Paulw11
広告を中央から周辺に変更したい、つまり広告データが次に変更されるとします。これは他のプロファイルと同様に単純なサービスまたは文字です。今あなたの質問は何ですか?データをデバイスに転送しましたか?あなたのデバイスはデータを更新しましたか? –
私は私の中央装置からの広告データを更新したい。また、私は周辺機器にいくつかの価値を保存する必要があります。 –