你有没有尝试过从地址簿中获取数据字段,然后进入ABPerson参考的奇妙世界,结果却发现它读起来像是太空火箭的蓝图?
到目前为止,我仍然需要帮助才能获得Twitter用户名、键和值:
//I tried this but I can't seem to get the if statement to work
ABMutableMultiValueRef socialMulti = ABRecordCopyValue(person, kABPersonSocialProfileProperty);
NSMutableDictionary *mySocialDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(socialMulti)];
NSLog(@"entering social dict of count %ld", ABMultiValueGetCount(socialMulti));
for (CFIndex i = 0; i < ABMultiValueGetCount(socialMulti); i++) {
CFStringRef socialLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(socialMulti, i));
CFStringRef social = ABMultiValueCopyValueAtIndex(socialMulti, i);
if ([(__bridge NSString*)socialLabel isEqualToString:@"twitter"]) {
NSLog(@"we got a twitter");
}
[mySocialDict setObject:(__bridge NSString*)social forKey:(__bridge NSString*)socialLabel];
NSLog(@"social is %@",social);
CFRelease(social);
CFRelease(socialLabel);}
实际上,我只对twitter用户名感兴趣。我知道我可以从我创建的字典中获得它,但我想直接获得它。无论如何,我计划取消NSDictionary步骤。
发布于 2012-06-21 06:17:19
下面是我的代码的摘录。根据需要替换您的var名称。
ABMultiValueRef socialMulti = ABRecordCopyValue(recordRef, kABPersonSocialProfileProperty);
NSMutableArray* twitterHandlesArray = [[NSMutableArray alloc] initWithCapacity:ABMultiValueGetCount(socialMulti)];
for (CFIndex i = 0; i < ABMultiValueGetCount(socialMulti); i++) {
NSDictionary* social = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(socialMulti, i);
if ([social[@"service"] isEqualToString:(__bridge NSString*)kABPersonSocialProfileServiceTwitter]) {
NSString* username = (NSString*)social[@"username"];
NSLog(@"we got a twitter. username is %@", username);
[twitterHandlesArray addObject:[[username conditionedAsTwitterHandle] SHA2Digest]];
}
}https://stackoverflow.com/questions/9073759
复制相似问题