Skip to content

Commit

Permalink
GUI now display error / warning messages on the main thread instead o…
Browse files Browse the repository at this point in the history
…f the callback thread
  • Loading branch information
Sebastien Stormacq committed Oct 28, 2010
1 parent db5efeb commit cdbd30b
Showing 1 changed file with 50 additions and 43 deletions.
93 changes: 50 additions & 43 deletions Classes/iPhoneStreamingPlayerAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// appreciated but not required.
//

#import <dispatch/dispatch.h>

#import "iPhoneStreamingPlayerAppDelegate.h"
#import "iPhoneStreamingPlayerViewController.h"
#import "AudioStreamer.h"
Expand Down Expand Up @@ -48,49 +50,54 @@ - (void)dealloc {

- (void)presentAlertWithTitle:(NSNotification *)notification
{
NSString *title = [[notification userInfo] objectForKey:@"title"];
NSString *message = [[notification userInfo] objectForKey:@"message"];
if (!uiIsVisible) {
#ifdef TARGET_OS_IPHONE
if(kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_4_0) {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = message;
localNotif.alertAction = NSLocalizedString(@"Open", @"");
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
}
#endif
}
else {
#ifdef TARGET_OS_IPHONE
UIAlertView *alert = [
[[UIAlertView alloc]
initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles: nil]
autorelease];
[alert
performSelector:@selector(show)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#else
NSAlert *alert =
[NSAlert
alertWithMessageText:title
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:message];
[alert
performSelector:@selector(runModal)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#endif
}
dispatch_queue_t main_queue = dispatch_get_main_queue();

dispatch_async(main_queue, ^{

NSString *title = [[notification userInfo] objectForKey:@"title"];
NSString *message = [[notification userInfo] objectForKey:@"message"];
if (!uiIsVisible) {
#ifdef TARGET_OS_IPHONE
if(kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_4_0) {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = message;
localNotif.alertAction = NSLocalizedString(@"Open", @"");
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
}
#endif
}
else {
#ifdef TARGET_OS_IPHONE
UIAlertView *alert = [
[[UIAlertView alloc]
initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles: nil]
autorelease];
[alert
performSelector:@selector(show)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#else
NSAlert *alert =
[NSAlert
alertWithMessageText:title
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:message];
[alert
performSelector:@selector(runModal)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#endif
}
});
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Expand Down

0 comments on commit cdbd30b

Please sign in to comment.