Find Favorite Contacts from the iOS Address Book API

Find Favorite contacts from the iOS Address Book API

Favorites are stored inside Phone.app, not inside the Address Book database itself. You can't access other app's sandbox on a non-jailbroken iPhone, so unfortunately the answer is no.

Also, it would be pretty bad for privacy if any app could see your favorite contacts. It's already bad that it can access entire address book without asking you.

How can I determine that CNContact is is favorites?

Filip Radelic answered same question:

Favorites are stored inside Phone.app, not inside the Address Book database itself. You can't access other app's sandbox on a non-jailbroken iPhone, so unfortunately the answer is no.

Also, it would be pretty bad for privacy if any app could see your favorite contacts. It's already bad that it can access entire address book without asking you.

Is there any way to get the Me card from iPhone Address Book API?

You could use the undocumented user default:

[[NSUserDefaults standardUserDefaults] objectForKey:@"SBFormattedPhoneNumber"];

and then search the address book for the card with that phone number.

Keep in mind that since the User Default is undocumented, Apple could change at any time and you may have trouble getting into the App Store.

Another approach you could take, although it is much more fragile, is to look at the device name. If the user hasn't changed it from the default "User Name's iPhone" AND they are using their real name as an iPhone, you could grab the user name from that. Again, not the best solution by any means, but it does give you something else to try.

The generally accepted answer to this question is to file a Radar with Apple for this feature and to prompt users to choose their card.

how to get contacts using address book API in ios programming?

Read and follow Apple's Address Book Programming Guide for iOS. Then come back here with specific questions if you encounter a problem.

User pick a contact from address book using new iOS 9's Contacts framework

I believe the solution you are looking for is CNContactPickerViewController. You can find the reference here. I also suggest watching the WWDC video about the new Contacts Framework, as there isn't too much information yet on Stack Overflow.

Sorry, but I do not know how to use NSPredicate in conjunction with this controller, and it is required.

Address book - Retrieving contacts

You are asking for the contacts before you have them apparently.
If you move this line

NSLog(@"contacts: %@", contacts); 

before this

        });
}
});

You should see the data.

The reason is, when you use dispach, and completion blocks, you are telling the system to run that code (usually in a different thread) after a certain operation has finished. So when you were printing the contacts, that block code had not run yet.

So whatever you need to do with the contacts, call it inside that block :)

Get a list of all contacts on iOS

Perhaps ABPerson function ABAddressBookCopyArrayOfAllPeople might do?

Example:

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
...
}


Related Topics



Leave a reply



Submit