From 5bd44bd639418da96cf890bbd9ca62122e60f0a6 Mon Sep 17 00:00:00 2001
From: Maxime Graulich <maxime.graulich@gmail.com>
Date: Thu, 12 Sep 2013 07:46:35 +0000
Subject: [PATCH] iOS: do not show Icon Badge & do not notify if onelab is
 foreground

---
 contrib/mobile/iOS/Onelab/AppDelegate.mm         | 6 ++++++
 contrib/mobile/iOS/Onelab/ModelViewController.mm | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm
index f4dc901f95..863f1df045 100644
--- a/contrib/mobile/iOS/Onelab/AppDelegate.mm
+++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm
@@ -50,4 +50,10 @@
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
 }
 
+-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
+{
+	application.applicationIconBadgeNumber = -1;
+	[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
+}
+
 @end
diff --git a/contrib/mobile/iOS/Onelab/ModelViewController.mm b/contrib/mobile/iOS/Onelab/ModelViewController.mm
index c3cd92fa04..8d0c5d5e46 100644
--- a/contrib/mobile/iOS/Onelab/ModelViewController.mm
+++ b/contrib/mobile/iOS/Onelab/ModelViewController.mm
@@ -140,9 +140,10 @@
         onelab_cb("compute");
         appDelegate->compute = NO;
 		UILocalNotification *localNotif = [[UILocalNotification alloc] init];
-		if (localNotif) {
+		if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground && localNotif) {
 			localNotif.alertBody = @"Computation finished";
 			localNotif.alertAction = @"View";
+			localNotif.hasAction = true;
 			localNotif.soundName = UILocalNotificationDefaultSoundName;
 			localNotif.applicationIconBadgeNumber = 1;
 			[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
@@ -152,6 +153,7 @@
     });
 	
 	dispatch_group_notify(group, dispatch_get_main_queue(), ^{
+		[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
 		[_runStopButton setAction:@selector(compute)];
 		[_runStopButton setTitle:@"Run"];
 		[_progressLabel setHidden:YES];
-- 
GitLab