diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index b7eeb00a2..654cec0ae 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -67,6 +67,7 @@ #ifdef HAVE_AMR @"YES",@"amr_8k_preference", // enable amr by default if compiled with #endif + //@"+33",@"countrycode_preference", nil]; [defaultsToRegister addEntriesFromDictionary:appDefaults]; diff --git a/Classes/LinphoneUI/LinphoneManager.h b/Classes/LinphoneUI/LinphoneManager.h index d817f5964..00ad141bc 100644 --- a/Classes/LinphoneUI/LinphoneManager.h +++ b/Classes/LinphoneUI/LinphoneManager.h @@ -54,6 +54,7 @@ typedef enum _Connectivity { -(void) enterBackgroundMode; -(void) becomeActive; -(void) kickOffNetworkConnection; +-(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log; @property (nonatomic, retain) id callDelegate; @property (nonatomic, retain) id registrationDelegate; diff --git a/Classes/LinphoneUI/LinphoneManager.m b/Classes/LinphoneUI/LinphoneManager.m index c75b91f5f..3be9f40e4 100644 --- a/Classes/LinphoneUI/LinphoneManager.m +++ b/Classes/LinphoneUI/LinphoneManager.m @@ -25,6 +25,8 @@ #include #import #import +#import + static LinphoneCore* theLinphoneCore=nil; static LinphoneManager* theLinphoneManager=nil; @@ -44,11 +46,87 @@ extern void libmsamr_init(); } return theLinphoneManager; } +-(NSString*) appendCountryCodeIfPossible:(NSString*) number { + if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) { + NSString* lCountryCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"countrycode_preference"]; + if (lCountryCode && [lCountryCode length]>0) { + //append country code + return [lCountryCode stringByAppendingString:number]; + } + } + return number; +} +-(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log { + ABAddressBookRef lAddressBook = ABAddressBookCreate(); + NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(lAddressBook); + for (id lContact in lContacts) { + ABMutableMultiValueRef lPhoneNumbers = ABRecordCopyValue((ABRecordRef)lContact, kABPersonPhoneProperty); + for ( int i=0; idir == LinphoneCallIncoming) { + lAddress=lLog->from; + } else { + lAddress=lLog->to; + } + const char* lUserName = linphone_address_get_username(lAddress); + if (!lUserName) { + //just return + return; + } + + NSString* lE164Number = [[NSString alloc] initWithCString:lUserName encoding:[NSString defaultCStringEncoding]]; + NSString* lDisplayName = [self getDisplayNameFromAddressBook:lE164Number andUpdateCallLog:lLog]; + + if(lDisplayName) { + linphone_address_set_display_name(lAddress, [lDisplayName cStringUsingEncoding:[NSString defaultCStringEncoding]]); + } else { + ms_message("No contact entry found for [%s] in address book",lUserName); + } + return; +} -(void) onCall:(LinphoneCall*) currentCall StateChanged: (LinphoneCallState) new_state withMessage: (const char *) message { - const char* lUserNameChars=linphone_address_get_username(linphone_call_get_remote_address(currentCall)); - NSString* lUserName = lUserNameChars?[[NSString alloc] initWithCString:lUserNameChars]:NSLocalizedString(@"Unknown",nil); - const char* lDisplayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(currentCall)); + const char* lUserNameChars=linphone_address_get_username(linphone_call_get_remote_address(currentCall)); + NSString* lUserName = lUserNameChars?[[NSString alloc] initWithCString:lUserNameChars]:NSLocalizedString(@"Unknown",nil); + if (new_state == LinphoneCallIncomingReceived) { + [self updateCallWithAddressBookData:currentCall]; // display name is updated + } + const char* lDisplayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(currentCall)); NSString* lDisplayName = lDisplayNameChars?[[NSString alloc] initWithCString:lDisplayNameChars]:@""; switch (new_state) { @@ -628,8 +706,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } -(void) becomeActive { - /*IOS specific*/ - linphone_core_start_dtmf_stream(theLinphoneCore); + if (theLinphoneCore == nil) { //back from standby and background mode is disabled [self startLibLinphone]; @@ -638,7 +715,9 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach linphone_core_refresh_registers(theLinphoneCore);//just to make sure REGISTRATION is up to date } - + /*IOS specific*/ + linphone_core_start_dtmf_stream(theLinphoneCore); + LCSipTransports transportValue; if (linphone_core_get_sip_transports(theLinphoneCore, &transportValue)) { ms_error("cannot get current transport"); @@ -662,4 +741,5 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach -(void) registerLogView:(id) view { mLogView = view; } + @end diff --git a/Classes/LinphoneUI/UICallButton.m b/Classes/LinphoneUI/UICallButton.m index ec015e9a8..9a05aaa6b 100644 --- a/Classes/LinphoneUI/UICallButton.m +++ b/Classes/LinphoneUI/UICallButton.m @@ -51,6 +51,12 @@ } else { char normalizedUserName[256]; NSString* toUserName = [NSString stringWithString:[mAddress text]]; + if ([mDisplayName.text length] <=0) { + NSString* lDisplayName = [[LinphoneManager instance] getDisplayNameFromAddressBook:toUserName andUpdateCallLog:nil]; + if (lDisplayName) { + mDisplayName.text = lDisplayName; + } + } linphone_proxy_config_normalize_number(proxyCfg,[toUserName cStringUsingEncoding:[NSString defaultCStringEncoding]],normalizedUserName,sizeof(normalizedUserName)); LinphoneAddress* tmpAddress = linphone_address_new(linphone_core_get_identity([LinphoneManager getLc])); linphone_address_set_username(tmpAddress,normalizedUserName); diff --git a/Classes/PhoneViewController.m b/Classes/PhoneViewController.m index 76c226cb6..4350dde71 100644 --- a/Classes/PhoneViewController.m +++ b/Classes/PhoneViewController.m @@ -244,14 +244,14 @@ if (notif) { notif.repeatInterval = 0; - notif.alertBody =[NSString stringWithFormat:NSLocalizedString(@" %@ is calling you",nil),username]; + notif.alertBody =[NSString stringWithFormat:NSLocalizedString(@" %@ is calling you",nil),displayName?displayName:username]; notif.alertAction = @"Answer"; notif.soundName = @"oldphone-mono-30s.caf"; [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; } } else { - mIncomingCallActionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@" %@ is calling you",nil),username] + mIncomingCallActionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@" %@ is calling you",nil),displayName?displayName:username] delegate:self cancelButtonTitle:NSLocalizedString(@"Decline",nil) destructiveButtonTitle:NSLocalizedString(@"Answer",nil)