Reputation: 303
I am using alert sheet to show the alert message. I put the alert sheet inside the main thread and i use more alert sheet like this but while running the app alert message appears.
But sometimes when the user click ok button in the alert message. The alert message not disappearing and i couldn’t do anything. the only thing i can do is to kill the app and restart it.
I checked the log file to catch the issue.but i couldn’t get the issue from the log file also all are normal there is no crash in the log file. I had checked more reference but i couldn’t find where the issue is arising. This is the example code.
dispatch_async(dispatch_get_main_queue(), ^{
NSAlert *alertView2 = [NSAlert alertWithMessageText:@"Server error occured. please check the internet connectivity" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@""];
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
int response;
[alertView2 beginSheetModalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(alertDidEndDoNothing:returnCode:contextInfo:)
contextInfo:&response];
});
Is the issue is due to the thread. It means two method gets called at the same time or the issue is in the alert sheet.
Upvotes: 0
Views: 296
Reputation: 770
I think you did all your work on Main thread using the "get_main" block so use the dispatch_async(dispatch_get_main_queue)
when you really needed not performance heavy task to the Main Tread it will freeze your UI and application.
Upvotes: 0