diff --git a/Classes/Contact.h b/Classes/Contact.h index 846884826..edeb22d0c 100644 --- a/Classes/Contact.h +++ b/Classes/Contact.h @@ -21,6 +21,7 @@ @property(nonatomic, strong) NSMutableArray *sipAddresses; @property(nonatomic, strong) NSMutableArray *emails; @property(nonatomic, strong) NSMutableArray *phoneNumbers; +@property BOOL added; - (void)setAvatar:(UIImage *)avatar; - (UIImage *)avatar:(BOOL)thumbnail; diff --git a/Classes/Contact.m b/Classes/Contact.m index 87b005abd..f3d3e959e 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -23,7 +23,7 @@ self = [super init]; _person = aperson; _friend = afriend ? linphone_friend_ref(afriend) : NULL; - + _added = FALSE; if (_person) { [self loadProperties]; @@ -355,11 +355,8 @@ (NSString *)kABPersonInstantMessageUsernameKey : value, (NSString *)kABPersonInstantMessageServiceKey : [LinphoneManager instance].contactSipField }; - // CFStringRef label = (__bridge CFStringRef)[[NSBundle mainBundle] - // objectForInfoDictionaryKey:@"CFBundleDisplayName"]; - // ABMultiValueAddValueAndLabel(lMap, (__bridge CFTypeRef)lDict, label, nil); - ABMultiValueReplaceLabelAtIndex(lMap, (__bridge CFTypeRef)(lDict), index); - if (!ABRecordSetValue(_person, kABPersonInstantMessageProperty, lMap, &error)) { + + if (![self replaceInProperty:kABPersonInstantMessageProperty value:(__bridge CFTypeRef)(lDict) atIndex:index]) { LOGI(@"Can't set contact with value [%@] cause [%@]", value, [(__bridge NSError *)error localizedDescription]); CFRelease(lMap); } else { @@ -374,6 +371,9 @@ if ([lDict objectForKey:(__bridge NSString *)kABPersonInstantMessageServiceKey] == nil) { /*too bad probably a gtalk number, storing uri*/ ret = [FastAddressBook normalizeSipURI:value]; + } else if (!_added) { + _added = TRUE; + [LinphoneManager.instance.fastAddressBook saveContact:self]; } CFRelease(lMap); } diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index ace16b470..4374fd214 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -384,6 +384,25 @@ static UICompositeViewDescription *compositeDescription = nil; } [self saveData]; [self.tableController.tableView reloadData]; + } else { + BOOL rm = TRUE; + for (NSString *sip in _contact.sipAddresses) { + if (![sip isEqualToString:@""]) { + rm = FALSE; + break; + } + } + if (rm) { + for (NSString *phone in _contact.phoneNumbers) { + if (![phone isEqualToString:@""]) { + rm = FALSE; + break; + } + } + } + if (rm) { + [LinphoneManager.instance.fastAddressBook removeContact:_contact]; + } } [self setEditing:FALSE];