forked from mirrors/linphone-iphone
Merge branch 'master' into tunnel
Conflicts: Classes/LinphoneUI/LinphoneManager.m
This commit is contained in:
commit
e71ec85e12
5 changed files with 99 additions and 8 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ typedef enum _Connectivity {
|
|||
-(void) enterBackgroundMode;
|
||||
-(void) becomeActive;
|
||||
-(void) kickOffNetworkConnection;
|
||||
-(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log;
|
||||
|
||||
@property (nonatomic, retain) id<LinphoneUICallDelegate> callDelegate;
|
||||
@property (nonatomic, retain) id<LinphoneUIRegistrationDelegate> registrationDelegate;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,14 @@
|
|||
#include <netdb.h>
|
||||
#import <AVFoundation/AVAudioSession.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
<<<<<<< HEAD
|
||||
#include "tunnel/TunnelManager.hh"
|
||||
|
||||
using namespace belledonnecomm;
|
||||
=======
|
||||
#import <AddressBook/AddressBook.h>
|
||||
|
||||
>>>>>>> master
|
||||
|
||||
static LinphoneCore* theLinphoneCore=nil;
|
||||
static LinphoneManager* theLinphoneManager=nil;
|
||||
|
|
@ -50,11 +55,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; i<ABMultiValueGetCount(lPhoneNumbers); i++) {
|
||||
CFStringRef lLabel = ABMultiValueCopyLabelAtIndex(lPhoneNumbers,i);
|
||||
CFStringRef lValue = ABMultiValueCopyValueAtIndex(lPhoneNumbers,i);
|
||||
CFStringRef lLocalizedLabel = ABAddressBookCopyLocalizedLabel(lLabel);
|
||||
NSString* lNormalizedNumber = [(NSString*)lValue stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
|
||||
lNormalizedNumber = [self appendCountryCodeIfPossible:lNormalizedNumber];
|
||||
number = [self appendCountryCodeIfPossible:number];
|
||||
|
||||
if([lNormalizedNumber isEqualToString:number]) {
|
||||
CFStringRef lDisplayName = ABRecordCopyCompositeName(lContact);
|
||||
|
||||
if (log) {
|
||||
//add phone type
|
||||
char ltmpString[256];
|
||||
CFStringRef lFormatedString = CFStringCreateWithFormat(NULL,NULL,CFSTR("phone_type:%@;"),lLocalizedLabel);
|
||||
CFStringGetCString(lFormatedString, ltmpString,sizeof(ltmpString), kCFStringEncodingUTF8);
|
||||
linphone_call_log_set_ref_key(log, ltmpString);
|
||||
CFRelease(lFormatedString);
|
||||
}
|
||||
return (NSString*)lDisplayName;
|
||||
}
|
||||
CFRelease(lLabel);
|
||||
CFRelease(lValue);
|
||||
CFRelease(lLocalizedLabel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
-(void) updateCallWithAddressBookData:(LinphoneCall*) call {
|
||||
//1 copy adress book
|
||||
LinphoneCallLog* lLog = linphone_call_get_call_log(call);
|
||||
LinphoneAddress* lAddress;
|
||||
if (lLog->dir == 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) {
|
||||
|
|
@ -650,8 +731,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];
|
||||
|
|
@ -660,7 +740,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");
|
||||
|
|
@ -684,4 +766,5 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
-(void) registerLogView:(id<LogView>) view {
|
||||
mLogView = view;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue