0

Objective-C でのブロックの操作に問題があります。私の問題は、関数 readDataFromCharactUUID の完了ブロックが do-while-loop を使用して呼び出されないことです。do-while-loop を使用しないと、一度呼び出されます。

私のコードでやりたいことは、値が 0x01 になるように頻繁に BLE 特性から値を読み取ることです。

私の質問: 完了ブロックが実行されないのはなぜですか? 私の場合、完了ブロックが実行されるようにするにはどうすればよいですか?

使用コード:

static bool dataReady = false;

-(IBAction)Buttonstartpressed:(UIButton *)sender{

LGLog(@"start pressed");

NSData *data = [NSData dataWithBytes:(unsigned char[]){CMD_Control_Learn} length:1];
[LGUtils writeData   :data
         charactUUID :CHARACTERISTIC_UUID_REMOTEBUDDYControl
         serviceUUID :SERVICE_UUID_REMOTEBUDDY
        peripheral   :_mBuddy completion:^(NSError *error)
        {
            // Befehl wurde übermittelt
            NSLog(@"Einlernen gesendet => Error : %@", error);

            do
            {
                // RB_Notification Data Ready auslesen
                [LGUtils readDataFromCharactUUID:CHARACTERISTIC_UUID_REMOTEBUDDYNotification
                                     serviceUUID:SERVICE_UUID_REMOTEBUDDY
                                      peripheral:_mBuddy
                                      completion:^(NSData *data, NSError *error)
                 {

                     NSLog(@"Data : %@ Error : %@", data, error);


                     const uint8_t *bytes = [data bytes]; // pointer to the bytes in data
                     int data_int = bytes[0]; // first byte

                     switch(data_int)
                     {
                         case 0x01:
                             NSLog(@"Data ready!");
                             dataReady = true;
                             break;
                         case 0x02:
                             NSLog(@"Data Transimission Error!");
                             break;
                         case 0x00:
                             NSLog(@"No Notification! => check again");
                             break;
                         default:
                             break;
                     }
                 }
                 ];
            }
            while(!dataReady);

        }];}

前もって感謝します!

4

1 に答える 1