diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.h b/contrib/mobile/iOS/Onelab/AppDelegate.h index 90fee7680199d21e8a786c9e57450e42030d6731..e06267808aed735af7a1d334bf473a8cca9d51b2 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.h +++ b/contrib/mobile/iOS/Onelab/AppDelegate.h @@ -5,7 +5,6 @@ @interface AppDelegate : UIResponder <UIApplicationDelegate>{ @public bool compute; - NSMutableArray *errors; } @property (strong, nonatomic) UIWindow *window; diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm index 056014f10b23d78090ff4636947ae62d373c608a..4f68ccd0ab71f07afc0a8e44ae8aa3997d0f2a67 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.mm +++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm @@ -14,7 +14,6 @@ self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; } compute = false; - errors = [[NSMutableArray alloc] init]; // Copy resource files if the version of the app has changed NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSString *prefsv = [prefs stringForKey:@"OnelabModelsVersion"]; diff --git a/contrib/mobile/iOS/Onelab/ModelViewController.mm b/contrib/mobile/iOS/Onelab/ModelViewController.mm index a8049674c278afa16bb5fb8898ce1b470e09f268..3b5f570293db73a8cf0a1e25f8f8b2b1e2206796 100644 --- a/contrib/mobile/iOS/Onelab/ModelViewController.mm +++ b/contrib/mobile/iOS/Onelab/ModelViewController.mm @@ -76,12 +76,6 @@ //[_loadingAlert release]; _loadingAlert = nil; } - - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - if(appDelegate->errors.count > 0){ - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; - [_errorAlert show]; - } } - (void)viewDidLoad @@ -182,11 +176,6 @@ [_progressLabel setHidden:YES]; [_progressIndicator stopAnimating]; [_progressIndicator setHidden:YES]; - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - if(appDelegate->errors.count > 0){ - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; - [_errorAlert show]; - } } - (void)stop @@ -310,26 +299,6 @@ return YES; } -#pragma mark - Alert view - --(void)addError:(std::string)msg -{ - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - NSString *str = [Utils getStringFromCString:msg.c_str()]; - // remove document path from error message - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *docPath = [[paths objectAtIndex:0] stringByAppendingString:@"/"]; - str = [str stringByReplacingOccurrencesOfString:docPath - withString:@""]; - [appDelegate->errors addObject:str]; -} - --(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex -{ - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - [appDelegate->errors removeAllObjects]; -} - #pragma mark - Split view -(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation @@ -347,8 +316,10 @@ void messageFromCpp (void *self, std::string level, std::string msg) [(__bridge id) self performSelectorOnMainThread:@selector(setProgress:) withObject:[Utils getStringFromCString:msg.c_str()] waitUntilDone:YES]; } - else if(level == "Error") - [(__bridge id)self addError:msg]; + else if(level == "Error"){ + [(__bridge id) self performSelectorOnMainThread:@selector(showError:) + withObject:[Utils getStringFromCString:msg.c_str()] waitUntilDone:YES]; + } } -(void)setProgress:(NSString *)progress @@ -356,6 +327,19 @@ void messageFromCpp (void *self, std::string level, std::string msg) [_progressLabel setText:progress]; } +-(void)showError:(NSString *)msg +{ + // only show first error + if(_errorAlert != nil && _errorAlert.visible) return; + // remove document path from error message + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *docPath = [[paths objectAtIndex:0] stringByAppendingString:@"/"]; + NSString *str = [msg stringByReplacingOccurrencesOfString:docPath withString:@""]; + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:str delegate:self + cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil]; + [_errorAlert show]; +} + -(void)handleProgressIndicatorTap:(id)sender { [_progressLabel setHidden:!_progressLabel.hidden];