0

I have used to ContactsManager of Kekiiwaa (https://github.com/Kekiiwaa/ContactsManager) and I dont know how to add a contact with multiple phone. Here is sample code for adding contact with one phone:

[self.contactsManager addContactName: @"Tefany"
                          lastName: @"Jhonson"
                            phones: @[@{@"label":@"mobile",@"value":@"731782982"}]
                            emails: @[@{@"label":@"work",@"value":@"tefany@work.com"}]
                          birthday: nil completion:^(BOOL wasAdded) {

    NSLog(@"%i",wasAdded);

}];

SO HOW DO I ADD CONTACT WITH MULTIPLE PHONE? I try to use: @[@{@"label":@"mobile",@"value":@"999999999999”},@{@"label":@"mobile",@"value":@"999999999999"}]

But It's won't work.

P/s: sorry with my bad English skill, thanks for your help!

  • Try by setting value for second key `label ` to @"work". Also set value for key `value` as 10 digits(like a standard mobile number). – ron27 Apr 05 '17 at 12:34
  • As I see ContactsManager is an old library and using AddressBook framework. Apple suggests using ContactsFramework if you target iOS 9 or later. `To work with the user’s contact information in apps that target iOS 9 and later, it’s recommended that you use the APIs defined in the Contacts and ContactsUI frameworks.` [Apple Contacts Framework](https://developer.apple.com/reference/contacts) – abdullahselek Apr 05 '17 at 15:42
  • Oh, i see. This app use AddressBook framework and I just maintain it. I have issues at adding contact with multiple phone. I will try Apple Contacts Framework for the next project. But can you help me to resolve my issues? – Cấn Khắc Nguyên Apr 06 '17 at 09:44

2 Answers2

0

I downloaded the repo from Github and try the code snippet below than it worked.

[self.contactsManager addContactName:@"Test"
                            lastName:@"Name"
                              phones:@[@{
                                           @"value":@"499034699748",
                                           @"label":@"Mobile"},
                                       @{
                                           @"value":@"349034699748",
                                           @"label":@"Home"
                                           }]
                              emails:@[@{
                                           @"value":@"mail@mail.com",
                                           @"label": @"home e-mail"
                                           }]
                            birthday:nil
                               image:nil
                          completion:^(BOOL wasAdded) {
                              NSLog(@"Contact was %@ added",wasAdded ? @"" : @"NOT");
                          }];

And for the label inside phone number dictionary Work also works.

abdullahselek
  • 7,893
  • 3
  • 50
  • 40
0

Oh, i have just done. The problem is here:

[phonesList enumerateObjectsUsingBlock:^(NSDictionary *phone, NSUInteger idx, BOOL *stop) {
    ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(phone[@"value"]), (__bridge CFStringRef)(phone[@"label"]), NULL);
    ABRecordSetValue(record, kABPersonPhoneProperty, multiPhone, nil);
}];

The lib is redeclaring with each dictionary in ARRAY phoneList, so the phone is created new instead adding to existing contact. So I think to add a contact with multiple phone number, need to get the multiphone out side block. And I have done with this:

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
[phonesList enumerateObjectsUsingBlock:^(NSDictionary *phone, NSUInteger idx, BOOL *stop) {
    ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(phone[@"value"]), (__bridge CFStringRef)(phone[@"label"]), NULL);
    ABRecordSetValue(record, kABPersonPhoneProperty, multiPhone, nil);
}];