ios - How to multithred correctly? UIAlertView is not displayed, only gray screen -
i have implemented texttospeech in project , want display alertview while text spoken. here calling methods texttospeech:
//-----before tts starts try display alertview cancelbutton //[self performselectoronmainthread:@selector(alertwhiletts) withobject:nil waituntildone:yes]; //gray view , no alertview //[self performselector:@selector(alertwhiletts)]; //gray view , no alertview //[self alertwhiletts]; //gray view , no alertview //this part here blocking, no gray screen, //after tts ready, alertview displayed dispatch_async(dispatch_get_main_queue(), ^{ //update ui if have [self alertwhiletts]; }); [[self view] setneedsdisplay]; [self synthesizeinbackground]; [queue waituntilalloperationsarefinished]; [self setisspeaking: false]; [[self view] setneedsdisplay]; here synthesizeinbackground method(in method synthesize starts tts):
- (void) synthesizeinbackground { queue = [[nsoperationqueue alloc] init]; operation = [[nsinvocationoperation alloc] initwithtarget:self selector:@selector(synthesize) object:nil]; [queue addoperation: operation]; } while tts want display alertview cancel button. in case getting gray screen without alertview.
how can call alertwhiletts correctly, alertview gets displayed?
here content of alertwhiletts:
- (void) alertwhiletts { uialertview *inboxread = [[[uialertview alloc] initwithtitle:@"inbox tts..." message:nil delegate:self cancelbuttontitle:@"abbrechen" otherbuttontitles:nil] autorelease]; inboxread.tag = 997; [inboxread show]; } update see solution, works:
[self performselectoronmainthread:@selector(alertwhiletts) withobject:nil waituntildone:yes]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, (unsigned long)null), ^(void) { [[self view] setneedsdisplay]; [self synthesizeinbackground]; [queue waituntilalloperationsarefinished]; [self setisspeaking: false]; [[self view] setneedsdisplay]; });
change alertwithttsto
uialertview *inboxread = [[[uialertview alloc] initwithtitle:@"inbox tts..." message:nil delegate:self cancelbuttontitle:@"abbrechen" otherbuttontitles:nil] autorelease]; inboxread.tag = 997; [inboxread show]; also dont forget call function alertwhiletts main ui thread doing
dispatch_async(dispatch_get_main_queue(), ^{ //update ui if have [self alertwhiletts]; });
Comments
Post a Comment