From a3ebd8f7d2ed636ea318d5ca8d162f465340dc51 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 29 Aug 2012 12:46:20 +0200 Subject: [PATCH] improve push notification support --- Classes/LinphoneAppDelegate.m | 10 ++++++++- Classes/LinphoneCoreSettingsStore.m | 7 +++++- Classes/LinphoneManager.h | 4 +++- Classes/LinphoneManager.m | 13 +++++++++-- Classes/PhoneMainView.m | 34 +++++++++++++++++------------ submodules/externals/exosip | 2 +- submodules/linphone | 2 +- 7 files changed, 51 insertions(+), 21 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 83199faa9..b3fe14791 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -207,11 +207,19 @@ NSDictionary *alert = [aps objectForKey:@"alert"]; if(alert != nil) { NSString *loc_key = [alert objectForKey:@"loc-key"]; + /*if we receive a remote notification, it is because our TCP background socket was no more working. + As a result, break it and refresh registers in order to make sure to receive incoming INVITE or MESSAGE*/ + LinphoneCore *lc=[LinphoneManager getLc]; + linphone_core_set_network_reachable(lc,FALSE); + linphone_core_set_network_reachable(lc,TRUE); if(loc_key != nil) { if([loc_key isEqualToString:@"IM_MSG"]) { [[LinphoneManager instance] addInhibitedEvent:kLinphoneTextReceivedSound]; [[PhoneMainView instance] changeCurrentView:[ChatViewController compositeViewDescription]]; - } + }else{ + //it's a call + [[LinphoneManager instance] didReceiveRemoteNotification]; + } } } } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 7d7ea463d..7258aad92 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -380,7 +380,12 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } // NSLocalizedString(@"IC_MSG", nil); // Fake for genstrings // NSLocalizedString(@"IM_MSG", nil); // Fake for genstrings - NSString *params = [NSString stringWithFormat:@"APN-TOK=%@;APN-MSG=IM_MSG;APN-CAL=IC_MSG;APN-CAL-SND=ring.caf;APN-MSG-SND=msg.caf", tokenString]; +#ifdef DEBUG + #define APPMODE_SUFFIX @"dev" +#else + #define APPMODE_SUFFIX @"prod" +#endif + NSString *params = [NSString stringWithFormat:@"app-id=%@.%@;pn-type=apple;pn-tok=%@;pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-call-snd=ring.caf;pn-msg-snd=msg.caf", [[NSBundle mainBundle] bundleIdentifier],APPMODE_SUFFIX,tokenString]; linphone_proxy_config_set_contact_parameters(proxyCfg, [params UTF8String]); } diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 0b435917a..44f35bed8 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -76,7 +76,7 @@ typedef struct _LinphoneManagerSounds { @private NSTimer* mIterateTimer; - + time_t lastRemoteNotificationTime; Connectivity connectivity; NSMutableArray *inhibitedEvent; @@ -101,6 +101,8 @@ typedef struct _LinphoneManagerSounds { - (BOOL)resignActive; - (void)becomeActive; - (BOOL)enterBackgroundMode; +- (void)didReceiveRemoteNotification; +- (BOOL)shouldAutoAcceptCall; + (void)kickOffNetworkConnection; - (void)setupNetworkReachabilityCallback; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a58e6a591..ec6877f05 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -116,7 +116,7 @@ struct codec_name_pref_table codec_pref_table[]={ + (NSSet *)unsupportedCodecs { NSMutableSet *set = [NSMutableSet set]; for(int i=0;codec_pref_table[i].name!=NULL;++i) { - if(linphone_core_find_payload_type([LinphoneManager getLc],codec_pref_table[i].name, codec_pref_table[i].rate) == NULL) { + if(linphone_core_find_payload_type([LinphoneManager getLc],codec_pref_table[i].name, codec_pref_table[i].rate,-1) == NULL) { [set addObject:codec_pref_table[i].prefname]; } } @@ -205,6 +205,7 @@ struct codec_name_pref_table codec_pref_table[]={ self.defaultExpires = 600; [self openDatabase]; [self copyDefaultSettings]; + lastRemoteNotificationTime=0; } return self; } @@ -663,7 +664,7 @@ static LinphoneCoreVTable linphonec_vtable = { ms_set_cpu_count(cpucount); if (![LinphoneManager isNotIphone3G]){ - PayloadType *pt=linphone_core_find_payload_type(theLinphoneCore,"SILK",24000); + PayloadType *pt=linphone_core_find_payload_type(theLinphoneCore,"SILK",24000,-1); if (pt) { linphone_core_enable_payload_type(theLinphoneCore,pt,FALSE); [LinphoneLogger logc:LinphoneLoggerWarning format:"SILK/24000 and video disabled on old iPhone 3G"]; @@ -713,6 +714,14 @@ static LinphoneCoreVTable linphonec_vtable = { } } +- (void)didReceiveRemoteNotification{ + lastRemoteNotificationTime=time(NULL); +} + +- (BOOL)shouldAutoAcceptCall{ + return lastRemoteNotificationTime!=0 && lastRemoteNotificationTime-time(NULL)<10; +} + - (BOOL)resignActive { if ([[LinphoneManager instance] settingsStore] != Nil) [[[LinphoneManager instance] settingsStore] synchronize]; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 7f05ae5e2..845764367 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -633,24 +633,30 @@ static PhoneMainView* phoneMainViewInstance=nil; if(address == nil) { address = @"Unknown"; } - - // Create a new notification - appData->notification = [[UILocalNotification alloc] init]; - if (appData->notification) { - appData->notification.repeatInterval = 0; - appData->notification.alertBody =[NSString stringWithFormat:NSLocalizedString(@"IC_MSG",nil), address]; - appData->notification.alertAction = NSLocalizedString(@"Answer", nil); - appData->notification.soundName = @"ring.caf"; - appData->notification.userInfo = [NSDictionary dictionaryWithObject:[NSData dataWithBytes:&call length:sizeof(call)] forKey:@"call"]; + if (![[LinphoneManager instance] shouldAutoAcceptCall]){ + // case where a remote notification is already received + // Create a new local notification + appData->notification = [[UILocalNotification alloc] init]; + if (appData->notification) { + appData->notification.repeatInterval = 0; + appData->notification.alertBody =[NSString stringWithFormat:NSLocalizedString(@"IC_MSG",nil), address]; + appData->notification.alertAction = NSLocalizedString(@"Answer", nil); + appData->notification.soundName = @"ring.caf"; + appData->notification.userInfo = [NSDictionary dictionaryWithObject:[NSData dataWithBytes:&call length:sizeof(call)] forKey:@"call"]; [[UIApplication sharedApplication] presentLocalNotificationNow:appData->notification]; + } } } else { - IncomingCallViewController *controller = DYNAMIC_CAST([self changeCurrentView:[IncomingCallViewController compositeViewDescription] push:TRUE],IncomingCallViewController); - if(controller != nil) { - [controller setCall:call]; - [controller setDelegate:self]; - } + if ([[LinphoneManager instance] shouldAutoAcceptCall]){ + linphone_core_accept_call(linphone_call_get_core(call),call); + }else{ + IncomingCallViewController *controller = DYNAMIC_CAST([self changeCurrentView:[IncomingCallViewController compositeViewDescription] push:TRUE],IncomingCallViewController); + if(controller != nil) { + [controller setCall:call]; + [controller setDelegate:self]; + } + } } } diff --git a/submodules/externals/exosip b/submodules/externals/exosip index dfe434328..6ba04c22c 160000 --- a/submodules/externals/exosip +++ b/submodules/externals/exosip @@ -1 +1 @@ -Subproject commit dfe434328c0b0cbbaee669d40b27e09fea5f49ab +Subproject commit 6ba04c22ccc8b140a9de84124d0e4ee7a406705b diff --git a/submodules/linphone b/submodules/linphone index 199108c92..bd6a97374 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 199108c92435cc0f7daf3dd8f6bdc6d9830b3af0 +Subproject commit bd6a9737485893b0bc08ffe75dfea6f71115b73c