How to add a contact with multiple phone value by ContactsManager(Kekiiwaa)

78 Views Asked by At

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":@"[email protected]"}]
                          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!

2

There are 2 best solutions below

0
On BEST ANSWER

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);
}];
0
On

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":@"[email protected]",
                                           @"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.