From 16bacbb87780ca96961ab05cdbebeb2b409587d4 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Tue, 4 Dec 2012 12:07:18 +0100 Subject: [PATCH] App does not indicate missed calls in App icon --- Classes/BuschJaegerConfiguration.h | 1 + Classes/BuschJaegerConfiguration.m | 33 ++++++++++++++++++++++++++++-- Classes/BuschJaegerHistoryView.m | 1 + Classes/BuschJaegerMainView.h | 4 ++++ Classes/BuschJaegerMainView.m | 28 +++++++++++++++++++++++++ Classes/BuschJaegerWelcomeView.m | 1 + 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Classes/BuschJaegerConfiguration.h b/Classes/BuschJaegerConfiguration.h index a492f866e..23db5ee4a 100644 --- a/Classes/BuschJaegerConfiguration.h +++ b/Classes/BuschJaegerConfiguration.h @@ -56,6 +56,7 @@ typedef enum _BuschJaegerConfigurationRequestType{ - (BOOL)parseQRCode:(NSString*)data delegate:(id)delegate; - (BOOL)loadHistory:(id)delegate; +- (NSMutableSet*)getHistory; - (BOOL)removeHistory:(History*)history delegate:(id)delegate; - (User*)getCurrentUser; diff --git a/Classes/BuschJaegerConfiguration.m b/Classes/BuschJaegerConfiguration.m index 6f6711923..19543d1fb 100644 --- a/Classes/BuschJaegerConfiguration.m +++ b/Classes/BuschJaegerConfiguration.m @@ -427,14 +427,43 @@ static NSString *const CONFIGURATION_HOME_AP_KEY = @"CONFIGURATION_HOME_AP_KEY"; return FALSE; } +- (NSMutableSet*)getHistory { + NSMutableSet *set; + NSString *url = ([self getCurrentRequestType] == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; + url = [self addUserNameAndPasswordToUrl:url]; + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5]; + if(request != nil) { + NSURLResponse *response = nil; + NSError *error = nil; + NSData *data = nil; + data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error delegate:self]; + if(data != nil){ + NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse*) response; + if(urlResponse.statusCode == 200) { + set = [[[NSMutableSet alloc] init] autorelease]; + NSString *dataString = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding: NSUTF8StringEncoding]; + NSArray *arr = [dataString componentsSeparatedByString:@"\n"]; + for (NSString *line in arr) { + if([line length]) { + History *his = [History parse:line]; + if(his) { + [set addObject:his]; + } + } + } + [dataString release]; + } + } + } + return set; +} + - (BOOL)loadHistory:(id)delegate { [history removeAllObjects]; NSString *url = ([self getCurrentRequestType] == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; url = [self addUserNameAndPasswordToUrl:url]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5]; if(request != nil) { - //[NSURLConnection connectionWithRequest:request delegate:self]; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { NSURLResponse *response = nil; NSError *error = nil; diff --git a/Classes/BuschJaegerHistoryView.m b/Classes/BuschJaegerHistoryView.m index f7f22dedc..3d0903fc2 100644 --- a/Classes/BuschJaegerHistoryView.m +++ b/Classes/BuschJaegerHistoryView.m @@ -103,6 +103,7 @@ #pragma mark - BuschJaegerConfigurationDelegate Functions - (void)buschJaegerConfigurationSuccess { + [[BuschJaegerMainView instance] updateIconBadge:nil]; [waitView setHidden:TRUE]; [self update]; } diff --git a/Classes/BuschJaegerMainView.h b/Classes/BuschJaegerMainView.h index 447723507..e16ed2408 100644 --- a/Classes/BuschJaegerMainView.h +++ b/Classes/BuschJaegerMainView.h @@ -33,6 +33,8 @@ @interface BuschJaegerMainView : UIViewController { @private int loadCount; + NSTimer *historyTimer; + NSOperationQueue *historyQueue; } @property (nonatomic, retain) IBOutlet UINavigationControllerEx *navigationController; @@ -43,6 +45,8 @@ @property (nonatomic, retain) IBOutlet BuschJaegerHistoryView *historyView; @property (nonatomic, retain) IBOutlet BuschJaegerHistoryDetailsView *historyDetailsView; +- (void)updateIconBadge:(id)info; + + (BuschJaegerMainView*) instance; @end diff --git a/Classes/BuschJaegerMainView.m b/Classes/BuschJaegerMainView.m index f70313d80..56cad40f2 100644 --- a/Classes/BuschJaegerMainView.m +++ b/Classes/BuschJaegerMainView.m @@ -90,6 +90,14 @@ static BuschJaegerMainView* mainViewInstance=nil; assert (!mainViewInstance); mainViewInstance = self; loadCount = 0; + historyTimer = [NSTimer scheduledTimerWithTimeInterval: 10.0 + target: self + selector: @selector(updateIconBadge:) + userInfo: nil + repeats: YES]; + historyQueue = [[NSOperationQueue alloc] init]; + historyQueue.name = @"History queue"; + historyQueue.maxConcurrentOperationCount = 1; } - (id)init { @@ -125,6 +133,9 @@ static BuschJaegerMainView* mainViewInstance=nil; [historyView release]; [historyDetailsView release]; + [historyTimer invalidate]; + [historyQueue release]; + // Remove all observer [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -148,6 +159,7 @@ static BuschJaegerMainView* mainViewInstance=nil; [self.view addSubview:view]; [navigationController pushViewController:welcomeView animated:FALSE]; [self networkUpdate:[[LinphoneManager instance].configuration.homeAP isEqualToData:[LinphoneManager getWifiData]]]; + [self updateIconBadge:nil]; } - (void)viewDidUnload { @@ -207,6 +219,21 @@ static BuschJaegerMainView* mainViewInstance=nil; #pragma mark - Event Functions +- (void)updateIconBadge:(id)info { + if([historyQueue operationCount] == 0) { + [historyQueue addOperationWithBlock:^(void) { + if([[LinphoneManager instance] configuration].valid) { + NSMutableSet *set = [[[LinphoneManager instance] configuration] getHistory]; + if(set != nil) { + int missed = [set count] - [[[LinphoneManager instance] configuration].history count]; + if(missed < 0) missed = 0; + [[UIApplication sharedApplication] setApplicationIconBadgeNumber:missed]; + } + } + }]; + } +} + - (void)callUpdateEvent: (NSNotification*) notif { LinphoneCall *call = [[notif.userInfo objectForKey: @"call"] pointerValue]; LinphoneCallState state = [[notif.userInfo objectForKey: @"state"] intValue]; @@ -272,6 +299,7 @@ static BuschJaegerMainView* mainViewInstance=nil; if ((linphone_core_get_calls([LinphoneManager getLc]) == NULL)) { [navigationController popToViewController:welcomeView animated:FALSE]; // No animation... Come back when Apple have learned how to create a good framework } + [self updateIconBadge:nil]; break; } default: diff --git a/Classes/BuschJaegerWelcomeView.m b/Classes/BuschJaegerWelcomeView.m index e0fe81163..b2635bbde 100644 --- a/Classes/BuschJaegerWelcomeView.m +++ b/Classes/BuschJaegerWelcomeView.m @@ -143,6 +143,7 @@ #pragma mark - BuschJaegerConfigurationDelegate Functions - (void)buschJaegerConfigurationSuccess { + [[BuschJaegerMainView instance] updateIconBadge:nil]; [waitView setHidden:TRUE]; [self update]; }