Rectangle 27 5

The phone numbers of a person in the Address Book are in the form of a multi-value property.

In your case, you should have something like the following (haven't tried it, typing directly here, so I don't know if it compiles and/or works):

ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *mobileNumber;
NSString *mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = (NSString *)ABMultiValueCopyLabelAtIndex(mobilePhones, i);
    if ([mobileLabel isEqualToString:@"mobile"]) {
        mobileNumber = (NSString*)ABMultiValueCopyValueAtIndex(mobilePhones,i);
        break;
    }
}

lancu, thank you for your reply. But I find that the solution may incorrect. the result is the same and I want to ask, what is the mobilePhones in the code? Thank you.

Sorry Mark, it should have been phoneNumbers :-). As I said, I typed it directly in the form, not in Xcode :-). So instead of mobilePhones, replace with phoneNumbers and it should be all good.

objective c - How to retrieve mobile numbers from iPhone Contacts. - S...

iphone objective-c contacts
Rectangle 27 2

The way to do this is by registering an external change callback. This way, your app will be notified of any changes to the address book as soon as they happen.

objective c - How whatsapp get updated contacts from addressbook faste...

ios objective-c abaddressbook whatsapp addressbookui
Rectangle 27 2

The way to do this is by registering an external change callback. This way, your app will be notified of any changes to the address book as soon as they happen.

objective c - How whatsapp get updated contacts from addressbook faste...

ios objective-c abaddressbook whatsapp addressbookui
Rectangle 27 0

Did you read the Address Book Programming Guide?

objective c - How to access contacts/email id in iphone app - Stack Ov...

iphone objective-c email
Rectangle 27 0

You can get address for all contacts as -

ABAddressBookRef addressBook = ABAddressBookCreate();

NSArray *contactArr = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

for (int i = 0; i < [contactArr count]; i++) 
{
    ABRecordRef person = (ABRecordRef)[contactArr objectAtIndex:i];

    ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);

    for(CFIndex j = 0; j < ABMultiValueGetCount(address); j++)
    {
        CFDictionaryRef addressDict = ABMultiValueCopyValueAtIndex(address, j);

        CFStringRef streetValue = CFDictionaryGetValue(addressDict, kABPersonAddressStreetKey);

        CFStringRef cityValue = CFDictionaryGetValue(addressDict, kABPersonAddressCityKey);

        CFStringRef stateValue = CFDictionaryGetValue(addressDict, kABPersonAddressStateKey);

        CFStringRef zipValue = CFDictionaryGetValue(addressDict, kABPersonAddressZIPKey);

        CFStringRef countryValue = CFDictionaryGetValue(addressDict, kABPersonAddressCountryKey);

    }

}

thanx for your great help.

objective c - how to get the home addresses of all contacts in the iph...

iphone objective-c
Rectangle 27 0

I would store the ABRecordID and then handle the situation for when they change although I have not personally seen a case where they change except when the user deletes all data and restores it from another source (moving from MobileMe to Google for example).

objective c - Address Book contacts in Core Data - Stack Overflow

objective-c iphone cocoa-touch core-data addressbook
Rectangle 27 0

For a search bar, have a look at TTSearchBar in the Three20 library.

Everything else can be easily implemented using UITableView.

objective c - How do I create a dictionary-style scroll bar for iPhone...

iphone objective-c
Rectangle 27 0

I agree with what David H said in his answer, you have a lot of work. To try to help you a bit, this will explain to you how to send an SMS.

Also here is a small code snippet that should give you an idea of how to get a phone number from an Address Book record:

ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef record = ABPersonCreate();
ABMutableMultiValueRef multi;
record = ABAddressBookGetPersonWithRecordID(addressBook, contactID);
multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
int multiCount = ABMultiValueGetCount(multi);
for(CFIndex i=0; i<multiCount; i++)
{
    [tempArrayPhones addObject:[NSString stringWithFormat:@"%@", (NSString *)ABMultiValueCopyValueAtIndex(multi, i)]];
}

Again this is not a complete code, it is just a snippet to give you an idea.

In shouldContinueAfterSelectingPerson I get the person, property and identifier, How can I get the phone number from them?

Already answered in my answer, it is ABMultiValueCopyValueAtIndex(multi, i). Since a person can have more than one phone number you need to use a ABMutableMultiValueRef to get the multiple numbers.

iphone - Objective c - send SMS / email to one of contacts in adress b...

iphone ios object abpeoplepickerview
Rectangle 27 0

Using ABPeoplePickerNavigationController you can only fetch the contacts from the Ipad or Iphone Address Book.

If you want same functionality with your structure data you need to make it all Custom Using UITableView and other views.

i m sure it might b done by sm1 and shared??

objective c - Showing custom contacts like iphone Address book - Stack...

iphone objective-c ios abaddressbook
Rectangle 27 0

The phone numbers of a person in the Address Book are in the form of a multi-value property.

In your case, you should have something like the following (haven't tried it, typing directly here, so I don't know if it compiles and/or works):

ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *mobileNumber;
NSString *mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = (NSString *)ABMultiValueCopyLabelAtIndex(mobilePhones, i);
    if ([mobileLabel isEqualToString:@"mobile"]) {
        mobileNumber = (NSString*)ABMultiValueCopyValueAtIndex(mobilePhones,i);
        break;
    }
}

lancu, thank you for your reply. But I find that the solution may incorrect. the result is the same and I want to ask, what is the mobilePhones in the code? Thank you.

Sorry Mark, it should have been phoneNumbers :-). As I said, I typed it directly in the form, not in Xcode :-). So instead of mobilePhones, replace with phoneNumbers and it should be all good.

objective c - How to retrieve mobile numbers from iPhone Contacts. - S...

iphone objective-c contacts
Rectangle 27 0

Looking at the documentation here (search Personal Information Properties), you can't. Maybe you will be able to do it when (if) we will get access to the FaceTime API's.

objective c - How do i get the instant messaging addresses from iphone...

iphone objective-c
Rectangle 27 0

You first need to save the Person to the address book before adding it to the group.

ABAddressBookRef ab = ABAddressBookCreate();
CFErrorRef error;
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@"new group", &error);
ABAddressBookAddRecord(ab, group, &error);
ABAddressBookSave(ab, &error);
//Create new person and save to this group
ABRecordRef record = ABPersonCreate();
BOOL isSuccess ;

isSuccess  = ABRecordSetValue(record, kABPersonNicknameProperty,@"GroupMember nick name", &error);
isSuccess = ABRecordSetValue(record, kABPersonMiddleNameProperty, @"Middle name", &error);

ABMutableMultiValueRef copyOfPhones = ABMultiValueCreateMutable(kABPersonPhoneProperty);

CFTypeRef phone= CFSTR("123000222111");

ABMultiValueAddValueAndLabel(copyOfPhones, phone,kABPersonPhoneMobileLabel,NULL);

isSuccess = ABRecordSetValue(record, kABPersonPhoneProperty, copyOfPhones, &error);

isSuccess = ABAddressBookAddRecord(ab, record, &error);
isSuccess = ABAddressBookSave(ab, &error);

ABGroupAddMember(group, record, &error);

NSLog(@"is success %d", isSuccess);

ABAddressBookSave(ab, &error);
CFRelease(group);

Thanks,Its works fine but I have one mutable array of all contacts and selected contact from that array I am trying to add into group,How can I do this? because my application is crashing ABRecordRef person = [contactArray objectAtIndex:i]; on this line.

objective c - Unable to add contacts into specific group in iphone usi...

iphone objective-c addressbook
Rectangle 27 0

ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record
ABRecordRef person = ABPersonCreate(); // create a person

NSString *phone = @"0123456789"; // the phone number to add

//Phone number is a list of phone number, so create a multivalue    
ABMutableMultiValueRef phoneNumberMultiValue  = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, phone, kABPersonPhoneMobileLabel, NULL);

ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil); // first name of the new person
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil); // his last name
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, &anError); // set the phone number property
ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record

ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookAddRecord(addressBook, group, &error); // add the group


ABAddressBookSave(addressBook, nil); //save the record



CFRelease(person); // relase the ABRecordRef  variable

thanks its working but can u please explain coding.... and how can i make group ??

hey code is working great and even making group but its not adding any contact !!!! :(

Its not adding an contact in group !!! its only creating group and showing contact in address book !!! Main thing is NOT ADDING IN GROUP

objective c - How to create contacts in address book in iPhone SDK? - ...

iphone objective-c cocoa-touch ios4 iphone-sdk-3.0
Rectangle 27 0

-(void)addContactInContactBook:(Info *)objInfo:(BOOL)isInsert:(BOOL)isUpdate:(BOOL)isDelete
{

if (isInsert)
{
    ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record
    ABRecordRef person = ABPersonCreate(); // create a person

    CFErrorRef  anError = NULL;
    ABMutableMultiValueRef phoneNumberMultiValue =
    ABMultiValueCreateMutable(kABPersonPhoneProperty);
    ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(objInfo.cellPhone),kABPersonPhoneMobileLabel, NULL);
    ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(objInfo.phone),kABPersonPhoneMainLabel, NULL);
    ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil); // set the phone number property


    // Address      
    ABMutableMultiValueRef address =
    ABMultiValueCreateMutable(kABDictionaryPropertyType);
    // Set up keys and values for the dictionary.
    CFStringRef keys[5];
    CFStringRef values[5];
    keys[0] = kABPersonAddressStreetKey;
    keys[1] = kABPersonAddressCityKey;
    keys[2] = kABPersonAddressStateKey;
    keys[3] = kABPersonAddressZIPKey;
    keys[4] = kABPersonAddressCountryKey;

    CFStringRef ref1 = (__bridge_retained CFStringRef)objInfo.street;

    CFStringRef ref2 = (__bridge_retained CFStringRef)objInfo.city;

    CFStringRef ref3 = (__bridge_retained CFStringRef)objInfo.state;

    CFStringRef ref4 = (__bridge_retained CFStringRef)objInfo.zipCode;

    CFStringRef ref5 = (__bridge_retained CFStringRef)objInfo.country;

    values[0] = ref1;
    values[1] = ref2;
    values[2] = ref3;
    values[3] = ref4;
    values[4] = ref5;



    CFDictionaryRef dicref = CFDictionaryCreate(kCFAllocatorDefault, (void *)keys, (void *)values, 5, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    ABMultiValueIdentifier identifier;
    ABMultiValueAddValueAndLabel(address, dicref, kABHomeLabel, &identifier);
    ABRecordSetValue(person, kABPersonAddressProperty, address,&anError);


    if (![objInfo.FName isEqualToString:@""])
        ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)objInfo.FName , nil); // first name of the new person
    if (![objInfo.LName isEqualToString:@""])
        ABRecordSetValue(person, kABPersonLastNameProperty, (__bridge CFTypeRef)(objInfo.LName), nil); // his last name
    //    ABRecordSetValue(person, kABPersonEmailProperty, (__bridge CFTypeRef)(txtEmail.text), nil);

    if (![objInfo.Email isEqualToString:@""])
    {
        ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFTypeRef)(objInfo.Email), (CFStringRef)@"Global", NULL);
        ABRecordSetValue(person, kABPersonURLProperty, emailMultiValue, nil);
    }
    ABRecordSetValue(person, kABPersonOrganizationProperty, (__bridge CFTypeRef)(objInfo.company), nil);
    //    CFRelease(emailMultiValue);

    ABRecordSetValue(person, kABPersonNoteProperty, (__bridge CFTypeRef)(objInfo.note), nil);


    ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record

    //    ABRecordRef group = ABGroupCreate(); //create a group
    //    ABRecordSetValue(group, kABGroupNameProperty,@"My Group", nil); // set group's name
    //    ABGroupAddMember(group, person, nil); // add the person to the group
    //    ABAddressBookAddRecord(addressBook, group, nil); // add the group


    BOOL isSaved = ABAddressBookSave(addressBook, &anError); //save the record

    if (isSaved) 
    {
        NSInteger num = ABRecordGetRecordID(person);

        NSString *qry = [NSString stringWithFormat:@"update %@ set phonebookId=%d,isSyncPhonebook='TRUE' where id = %d",TABLE,num,objInfo.infoId];
        [appDel insertORUpdateInfo:qry];
    }

}
else if(isUpdate)
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, objInfo.phonebookId);
    if(person != NULL)
    {
        CFErrorRef  anError = NULL;
        ABMutableMultiValueRef phoneNumberMultiValue =
        ABMultiValueCreateMutable(kABPersonPhoneProperty);
        ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(objInfo.cellPhone),kABPersonPhoneMobileLabel, NULL);
        ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,(__bridge CFTypeRef)(objInfo.phone),kABPersonPhoneMainLabel, NULL);
        ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil); // set the phone number property


        // Address      
        ABMutableMultiValueRef address =
        ABMultiValueCreateMutable(kABDictionaryPropertyType);
        // Set up keys and values for the dictionary.
        CFStringRef keys[5];
        CFStringRef values[5];
        keys[0] = kABPersonAddressStreetKey;
        keys[1] = kABPersonAddressCityKey;
        keys[2] = kABPersonAddressStateKey;
        keys[3] = kABPersonAddressZIPKey;
        keys[4] = kABPersonAddressCountryKey;

        CFStringRef ref1 = (__bridge_retained CFStringRef)objInfo.street;

        CFStringRef ref2 = (__bridge_retained CFStringRef)objInfo.city;

        CFStringRef ref3 = (__bridge_retained CFStringRef)objInfo.state;

        CFStringRef ref4 = (__bridge_retained CFStringRef)objInfo.zipCode;

        CFStringRef ref5 = (__bridge_retained CFStringRef)objInfo.country;

        values[0] = ref1;
        values[1] = ref2;
        values[2] = ref3;
        values[3] = ref4;
        values[4] = ref5;



        CFDictionaryRef dicref = CFDictionaryCreate(kCFAllocatorDefault, (void *)keys, (void *)values, 5, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

        ABMultiValueIdentifier identifier;
        ABMultiValueAddValueAndLabel(address, dicref, kABHomeLabel, &identifier);
        ABRecordSetValue(person, kABPersonAddressProperty, address,&anError);


        if (![objInfo.FName isEqualToString:@""])
            ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)objInfo.FName , nil); // first name of the new person
        if (![objInfo.LName isEqualToString:@""])
            ABRecordSetValue(person, kABPersonLastNameProperty, (__bridge CFTypeRef)(objInfo.LName), nil); // his last name
        //    ABRecordSetValue(person, kABPersonEmailProperty, (__bridge CFTypeRef)(txtEmail.text), nil);

        if (![objInfo.Email isEqualToString:@""])
        {
            ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
            ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFTypeRef)(objInfo.Email), (CFStringRef)@"Global", NULL);
            ABRecordSetValue(person, kABPersonURLProperty, emailMultiValue, nil);
        }
        ABRecordSetValue(person, kABPersonOrganizationProperty, (__bridge CFTypeRef)(objInfo.company), nil);
        //    CFRelease(emailMultiValue);

        ABRecordSetValue(person, kABPersonNoteProperty, (__bridge CFTypeRef)(objInfo.note), nil);


        //        ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record

        //    ABRecordRef group = ABGroupCreate(); //create a group
        //    ABRecordSetValue(group, kABGroupNameProperty,@"My Group", nil); // set group's name
        //    ABGroupAddMember(group, person, nil); // add the person to the group
        //    ABAddressBookAddRecord(addressBook, group, nil); // add the group


        BOOL isSaved = ABAddressBookSave(addressBook, &anError); //save the record

        if (isSaved) 
        {
//                NSInteger num = ABRecordGetRecordID(person);

            NSString *qry = [NSString stringWithFormat:@"update %@ set isUpdatePhonebook='TRUE' where id = %d",TABLE,objInfo.infoId];
            [appDel insertORUpdateInfo:qry];
        }

    }
//        ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record
//        ABRecordRef person = ABPersonCreate(); // create a person


}
else if(isDelete)
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, objInfo.phonebookId);
    if(person != NULL)
    {
        CFErrorRef  anError = NULL;
        ABAddressBookRemoveRecord(addressBook, person, &anError);
        BOOL isSaved = ABAddressBookSave(addressBook, &anError); //save the record

        if (isSaved) 
        {
//                NSInteger num = ABRecordGetRecordID(person);

            NSString *qry = [NSString stringWithFormat:@"update %@ set isDeletePhonebook='TRUE' where id = %d",TABLE,objInfo.infoId];
            [appDel insertORUpdateInfo:qry];
        }

    }
}

//    CFRelease(person); // relase the ABRecordRef  variable

}

does this work if user has multiple home or work addressess..?? I have a problem saving multiple home or multiple work addresses.

objective c - How to create contacts in address book in iPhone SDK? - ...

iphone objective-c cocoa-touch ios4 iphone-sdk-3.0
Rectangle 27 0

ABRecordGetRecordID() is the API that you can use. However, apple documentation does states some noteworthy points about the ABRecordID returned by this API.

Every record in the Address Book database has a unique record identifier. This identifier always refers to the same record, unless that record is deleted or the data is reset. Record identifiers can be safely passed between threads. They are not guaranteed to remain the same across devices.

The suggested method as per apple guidelines is

The recommended way to keep a long-term reference to a particular record is to store the first and last name, or a hash of the first and last name, in addition to the identifier. When you look up a record by ID, compare the records name to your stored name. If they dont match, use the stored name to find the record, and store the new ID for the record.

In my app, I am also checking for creation date of the contact since the name against the ABRecordID could have been changed by the user. Creation date of a contact DOES NOT change upon device reset.

objective c - Is there a "uniqueID" type property for address book con...

objective-c ios addressbook uniqueidentifier abaddressbook
Rectangle 27 0

Add alphabetic sections to ur tableview, then You have to create array of alphabets corresponding to the section in tableview. Like section[0] - 'A', section[1] - 'B', etc.

Add - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return keys; } //the delegate is asking for an array of the values to display in the index.

So the first item in this array will take the user to the first section, which is section 0.

objective c - Displaying Elements in UITableView like iPhone contacts,...

iphone objective-c arrays uitableview sorting
Rectangle 27 0

Building up on Daij-Djan's answer, since this is the approach I use and it doesn't require any code:

Though you mention the mac, as a last resort, if using a windows PC, you can add contacts vcf to your user directory\contacts folder, then have iTunes sync them. Once you sync them with your device they should be in your device. The contacts can be from external software like Microsoft outlook or any sort of exported contacts.

objective c - Get list of Address Book Contacts and Import into iPhone...

iphone objective-c ios contacts addressbook
Rectangle 27 0

I'm sorry to say you have a lot of work ahead of you. First, once the contact is selected by the user, then you need to extract the phone or email yourself. If there are multiple tel numbers or email addresses, you probably should then prompt the user which one to use - by using a UIActionSheet or a table. With a phone number, you can create a telephone URL and send that to the shared application, which causes a call to be made (there are lots of examples here on how to do that).

With an email address, you need to use MFMailComposeViewController to create an email, and then you add the one known address in for the user through the delegate. There is also a sister class, MFMessageComposeViewController, for sending SMS messages.

I did this exact same thing for my company and it took me about 3 days to code and test the whole thing (all 3 options).

EDIT: A person can have multiple phone numbers and email addresses. You have two choices here:

Thanks for your reply, I looked at shouldContinueAfterSelectingPerson docs and it says: "Return YES if you want default action to be performed" what is default action?

Hmm - interesting - well, I believe what should happen if you return YES is that iOS will switch to the Phone app, Messages, or Mail depending on what you tapped on. A couple of things: you need to have a strong reference to ABPeoplePickerNavigationController after you return YES (so that class is not released before it contacts the system). Did you add a log message so you know you in fact returned YES? Can you log the value too - of what was tapped. Try adding some dummy email addresses in a contact so you know for sure they are properly formatted. Is problem on device or simulator?

anyway id the default behavior is as u say it's not what I want.. Do you know how do I get the phone number of the contact?

iphone - Objective c - send SMS / email to one of contacts in adress b...

iphone ios object abpeoplepickerview
Rectangle 27 0

See Apples online Documentation on how to handle changing ids and what to store.

objective c - Address Book contacts in Core Data - Stack Overflow

objective-c iphone cocoa-touch core-data addressbook