I have to show the contacts from facebook into my application.I am not getting how to do this. I am using this code but not getting any contact list. I am getting this type in the array but not getting any facebook list of contacts.
<__NSArrayM 0x608000457430>(
<CPRecord: 0x7fd37d5c3290 ABPerson>,
<CPRecord: 0x7fd37d5c34c0 ABPerson>,
<CPRecord: 0x7fd37d5c3d60 ABPerson>,
<CPRecord: 0x7fd37d5c3f90 ABPerson>,
<CPRecord: 0x7fd37d5c42e0 ABPerson>,
<CPRecord: 0x7fd37d5c4630 ABPerson>,
<CPRecord: 0x7fd37d5c4980 ABPerson>,
<CPRecord: 0x7fd37d5c4df0 ABPerson>,
<CPRecord: 0x7fd37d5c5140 ABPerson>,
<CPRecord: 0x7fd37d5c5490 ABPerson>,
<CPRecord: 0x7fd37d5c57e0 ABPerson>,
<CPRecord: 0x7fd37d5c5c50 ABPerson>,
<CPRecord: 0x7fd37d5c5fa0 ABPerson>,
<CPRecord: 0x7fd37d5c62f0 ABPerson>,
<CPRecord: 0x7fd37d5c6640 ABPerson>,
<CPRecord: 0x7fd37d404e10 ABPerson>,
<CPRecord: 0x7fd37d450e00 ABPerson>,
<CPRecord: 0x7fd37d460370 ABPerson>,
<CPRecord: 0x7fd37d460930 ABPerson>,
<CPRecord: 0x7fd37d44f730 ABPerson>,
<CPRecord: 0x7fd37d44f960 ABPerson>,
<CPRecord: 0x7fd37d460ff0 ABPerson>,
<CPRecord: 0x7fd37d461460 ABPerson>,
<CPRecord: 0x7fd37d4617b0 ABPerson>,
<CPRecord: 0x7fd37d461b00 ABPerson>,
<CPRecord: 0x7fd37d461fa0 ABPerson>,
<CPRecord: 0x7fd37d4624f0 ABPerson>,
Please help.
if (&ABAddressBookRequestAccessWithCompletion) { // if in iOS 6
// Request authorization to Address Book
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
[self getFacebookContacts:addressBookRef];
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
[self getFacebookContacts:addressBookRef];
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
}
}
else{ // if not in iOS 6
ABAddressBookRef addressBookRef = ABAddressBookCreate();
[self getFacebookContacts:addressBookRef];
NSLog(@"Not ios 6");
}
-(void) getFacebookContacts:(ABAddressBookRef) addressBookRef
{
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
CFIndex contactCount = CFArrayGetCount(allContacts);
// Traverse through contacts
for(int i=0; i<contactCount; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(allContacts, i);
//Check if contact has social profile
ABMultiValueRef social = ABRecordCopyValue(( ABRecordRef)ref, kABPersonSocialProfileProperty);
if (social) {
// ***** This is coming as 0 **********
CFIndex count = ABMultiValueGetCount(social);
for (int i = 0 ; i < count; i++) {
CFDictionaryRef socialValue = ABMultiValueCopyValueAtIndex(social, i);
if(CFStringCompare( CFDictionaryGetValue(socialValue, kABPersonSocialProfileServiceKey), kABPersonSocialProfileServiceFacebook, 0)==kCFCompareEqualTo) {
NSLog(@"Facebook Contact %d : %@",i, (NSString*) CFDictionaryGetValue(socialValue, kABPersonSocialProfileUserIdentifierKey));
}
}
}
}
}