forked from mirrors/linphone-iphone
contact: convert phone numbers to sip uri when needed
This commit is contained in:
parent
6c55111170
commit
01ab2ed4c5
5 changed files with 21 additions and 46 deletions
|
|
@ -180,7 +180,7 @@
|
|||
[cell.editTextfield setKeyboardType:UIKeyboardTypeEmailAddress];
|
||||
}
|
||||
|
||||
[cell setAddress:value];
|
||||
[cell setAddress:value isPhone:(indexPath.section == ContactSections_Number)];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
@property(weak, nonatomic) IBOutlet UIIconButton *chatButton;
|
||||
|
||||
- (id)initWithIdentifier:(NSString *)identifier;
|
||||
- (void)setAddress:(NSString *)address;
|
||||
- (void)setAddress:(NSString *)address isPhone:(BOOL)phone;
|
||||
- (void)hideDeleteButton:(BOOL)hidden;
|
||||
|
||||
- (IBAction)onCallClick:(id)sender;
|
||||
|
|
|
|||
|
|
@ -40,9 +40,18 @@
|
|||
|
||||
#pragma mark - UITableViewCell Functions
|
||||
|
||||
- (void)setAddress:(NSString *)address {
|
||||
_addressLabel.text = _editTextfield.text = address;
|
||||
- (void)setAddress:(NSString *)address isPhone:(BOOL)phone {
|
||||
NSString *name = address;
|
||||
if (phone) {
|
||||
char *normalizedPhone = linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC),
|
||||
address.UTF8String);
|
||||
if (normalizedPhone) {
|
||||
name = [NSString stringWithUTF8String:normalizedPhone];
|
||||
ms_free(normalizedPhone);
|
||||
}
|
||||
}
|
||||
|
||||
_addressLabel.text = _editTextfield.text = name;
|
||||
LinphoneAddress *addr = linphone_core_interpret_url(LC, _addressLabel.text.UTF8String);
|
||||
_chatButton.enabled = _callButton.enabled = (addr != NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,8 +47,6 @@
|
|||
+ (NSString *)displayNameForAddress:(const LinphoneAddress *)addr;
|
||||
|
||||
+ (BOOL)isSipURI:(NSString *)address; // should be removed
|
||||
+ (NSString *)appendCountryCodeIfPossible:(NSString *)number; // should be removed
|
||||
+ (NSString *)normalizePhoneNumber:(NSString *)number; // should be removed
|
||||
+ (NSString *)normalizeSipURI:(NSString *)address; // should be removed
|
||||
|
||||
+ (NSString *)localizedLabel:(NSString *)label;
|
||||
|
|
|
|||
|
|
@ -74,17 +74,6 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
|
|||
return [address hasPrefix:@"sip:"] || [address hasPrefix:@"sips:"];
|
||||
}
|
||||
|
||||
+ (NSString *)appendCountryCodeIfPossible:(NSString *)number {
|
||||
if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) {
|
||||
NSString *lCountryCode = [LinphoneManager.instance lpConfigStringForKey:@"countrycode_preference"];
|
||||
if (lCountryCode && [lCountryCode length] > 0) {
|
||||
// append country code
|
||||
return [lCountryCode stringByAppendingString:number];
|
||||
}
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
+ (NSString *)normalizeSipURI:(NSString *)address {
|
||||
// replace all whitespaces (non-breakable, utf8 nbsp etc.) by the "classical" whitespace
|
||||
address = [[address componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
|
||||
|
|
@ -107,27 +96,6 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
|
|||
return normalizedSipAddress;
|
||||
}
|
||||
|
||||
+ (NSString *)normalizePhoneNumber:(NSString *)address {
|
||||
NSMutableString *lNormalizedAddress = [NSMutableString stringWithString:address];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@" "
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@"("
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@")"
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@"-"
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
return [FastAddressBook appendCountryCodeIfPossible:lNormalizedAddress];
|
||||
}
|
||||
|
||||
+ (BOOL)isAuthorized {
|
||||
return ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized;
|
||||
}
|
||||
|
|
@ -189,14 +157,14 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
|
|||
if (lMap) {
|
||||
for (int i = 0; i < ABMultiValueGetCount(lMap); i++) {
|
||||
CFStringRef lValue = ABMultiValueCopyValueAtIndex(lMap, i);
|
||||
|
||||
NSString *lNormalizedKey = [FastAddressBook normalizePhoneNumber:(__bridge NSString *)(lValue)];
|
||||
NSString *lNormalizedSipKey = [FastAddressBook normalizeSipURI:lNormalizedKey];
|
||||
if (lNormalizedSipKey != NULL)
|
||||
lNormalizedKey = lNormalizedSipKey;
|
||||
|
||||
[_addressBookMap setObject:(__bridge id)(lPerson) forKey:lNormalizedKey];
|
||||
|
||||
char *normalizedPhone = linphone_proxy_config_normalize_phone_number(
|
||||
linphone_core_get_default_proxy_config(LC), ((__bridge NSString *)(lValue)).UTF8String);
|
||||
NSString *name = [FastAddressBook
|
||||
normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone]
|
||||
: (__bridge NSString *)(lValue)];
|
||||
[_addressBookMap setObject:(__bridge id)(lPerson) forKey:name];
|
||||
if (normalizedPhone)
|
||||
ms_free(normalizedPhone);
|
||||
CFRelease(lValue);
|
||||
}
|
||||
CFRelease(lMap);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue