Estoy tratando de obtener el ID de una etiqueta, usando una biblioteca.haga algo de trabajo en segundo plano y devuelva el resultado
Se me ocurrió lo siguiente. el bucle que busca una etiqueta se hace en segundo plano y obtengo un resultado correcto en tagAsString.
-(void) readTag {
NSLog(@"readTag");
unsigned char * tagUID = (unsigned char *) malloc(M1K_UID_SIZE * sizeof(char));
//work to do in the background
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ERR ret;
while ((ret = scanner->IsTagAvailable(tagUID)) != ERR_TAG_AVAILABLE) {
NSLog(@"ret: %d", ret);
}
//main thread
dispatch_async(dispatch_get_main_queue(), ^{
if(ret == ERR_TAG_AVAILABLE) {
NSLog(@"tag available");
NSString *tagAsString = [[[NSString alloc] initWithFormat:@"%x%x%x%x", tagUID[0],tagUID[1],tagUID[2],tagUID[3]] retain];
}
});
});
}
Me gustaría ser capaz de devolver ese valor, así que sería capaz de llamar a:
NSString * myTag = [self readTag];
es posible? Gracias por su ayuda, Michael
Gracias por su respuesta. ¿Quiere decir usar NSNotification para notificar o hay alguna otra manera? – Themikebe
NSNotification es una manera posible, sin embargo, en este ejemplo solo usaría message passing (llamadas a métodos). Editaré mi respuesta con un ejemplo – jjwchoy