J'essaie d'obtenir l'ID d'une étiquette, en utilisant une bibliothèque.faire un travail en arrière-plan et retourner le résultat
J'ai trouvé ce qui suit. la boucle qui cherche un tag est faite en arrière-plan et j'obtiens un résultat correct dans 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];
}
});
});
}
Je voudrais être en mesure de retourner cette valeur si je serais en mesure d'appeler:
NSString * myTag = [self readTag];
est-ce possible? Merci pour votre aide, Michael
Merci pour votre réponse. Voulez-vous dire utiliser une NSNotification pour notifier ou existe-t-il un autre moyen? – Themikebe
NSNotification est une façon possible, mais dans cet exemple, j'utiliserais simplement le passage de message (appels de méthode). Je vais éditer ma réponse avec un exemple – jjwchoy