App does not indicate missed calls in App icon

This commit is contained in:
Yann Diorcet 2012-12-04 12:07:18 +01:00
parent 6d631eb308
commit 16bacbb877
6 changed files with 66 additions and 2 deletions

View file

@ -56,6 +56,7 @@ typedef enum _BuschJaegerConfigurationRequestType{
- (BOOL)parseQRCode:(NSString*)data delegate:(id<BuschJaegerConfigurationDelegate>)delegate;
- (BOOL)loadHistory:(id<BuschJaegerConfigurationDelegate>)delegate;
- (NSMutableSet*)getHistory;
- (BOOL)removeHistory:(History*)history delegate:(id<BuschJaegerConfigurationDelegate>)delegate;
- (User*)getCurrentUser;

View file

@ -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<BuschJaegerConfigurationDelegate>)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;

View file

@ -103,6 +103,7 @@
#pragma mark - BuschJaegerConfigurationDelegate Functions
- (void)buschJaegerConfigurationSuccess {
[[BuschJaegerMainView instance] updateIconBadge:nil];
[waitView setHidden:TRUE];
[self update];
}

View file

@ -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

View file

@ -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:

View file

@ -143,6 +143,7 @@
#pragma mark - BuschJaegerConfigurationDelegate Functions
- (void)buschJaegerConfigurationSuccess {
[[BuschJaegerMainView instance] updateIconBadge:nil];
[waitView setHidden:TRUE];
[self update];
}