gpt4 book ai didi

iphone - 从通讯录中仅获取Facebook联系人

转载 作者:行者123 更新时间:2023-12-01 16:51:25 25 4
gpt4 key购买 nike

我只需要从通讯录中获取Facebook联系人。我经历了很多线程,并提出了以下代码。

- (IBAction)buttonPressed:(id)sender {
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, kABPersonSocialProfileUsernameKey));
}
}
}
}
}

由于我的社交资料计数为0,因此我无法获取任何联系人。从设置-> Facebook同步我的Facebook帐户后,通讯录中添加了许多联系人

请检查代码,并让我知道是否有任何建议或我做错了什么。

最佳答案

您正在尝试获取kABPersonSocialProfileUsernameKey,但它可以为空。尝试使用kABPersonSocialProfileUserIdentifierKey。

关于iphone - 从通讯录中仅获取Facebook联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15378371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com