Objective-C의 블록으로 작업하는 데 문제가 있습니다. 내 문제는 readDataFromCharactUUID 함수의 완료 블록이 do-while-loop를 사용하여 호출되지 않는다는 것입니다. do-while-loop를 사용하지 않고는 한 번 호출됩니다.objective-c 블록 및 do-while 루프
내 코드로 수행하고자하는 작업은 값이 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);
}];}
사전에 감사합니다!
이 가진 모든 행운? – Miknash