如何在iOS中写Facebook / Twitter来通讯录? [英] How to write Facebook/Twitter to address book in iOS?

查看:262
本文介绍了如何在iOS中写Facebook / Twitter来通讯录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我将一些数据导出到通讯簿,以创建一些新的联系人条目。除了Facebook和Twitter地址之外,我可以导出我想要的所有东西。我完全失去了这两个。



以下是我用于导出非Facebook / Twitter数据的代码:

  ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
ABMultiValueAddValueAndLabel(multiPhone,(__bridge CFTypeRef)(phoneMobile),kABPersonPhoneMobileLabel,NULL);
ABMultiValueAddValueAndLabel(multiPhone,(__bridge CFTypeRef)(thePhoneHome),kABHomeLabel,NULL);
ABRecordSetValue(newPerson,kABPersonPhoneProperty,multiPhone,NULL);
CFRelease(multiPhone);

以下是我尝试导出不起作用的Facbeook:

  ABMutableMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
ABMultiValueAddValueAndLabel(multiSocial,(__bridge CFTypeRef)(theFacebook),kABPersonSocialProfileServiceFacebook,NULL);
ABRecordSetValue(newPerson,kABPersonSocialProfileProperty,multiSocial,NULL);
CFRelease(multiSocial);

我在哪里出错?

解决方案

由于某些原因,设置社交个人资料非常棘手,但是这里需要执行以下代码:

  ABMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 

ABMultiValueAddValueAndLabel(multi_ocial,(__bridge CFTypeRef)([NSDictionary dictionaryWithObjectsAndKeys:(NSString *)kABPersonSocialProfileServiceFacebook,kABPersonSocialProfileServiceKey,theFacebook,kABPersonSocialProfileUsernameKey,nil]),kABPersonSocialProfileServiceFacebook,NULL);

ABRecordSetValue(newPerson,kABPersonSocialProfileProperty,multiSocial,NULL);

根据文档,社交配置文件是一个kABMultiDictionaryPropertyType,而不是kABMultiStringType。



这也意味着您需要添加字典到 multiSocial 而不是字符串。该格式对我来说没有意义,所以只要复制和粘贴,当你需要使用它。



然后,你设置它以前做了什么。 / p>

In my app I export some data to the address book in order to create some new contact entries. I can export everything I want to without problem, except Facebook and Twitter addresses. I'm completely lost on these two.

Here's some code I'm using to export non-Facebook/Twitter data that DOES work:

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(thePhoneMobile), kABPersonPhoneMobileLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(thePhoneHome), kABHomeLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone, NULL);
CFRelease(multiPhone);

Here's how I'm trying to export Facbeook which does NOT work:

ABMutableMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiSocial, (__bridge CFTypeRef)(theFacebook), kABPersonSocialProfileServiceFacebook, NULL);
ABRecordSetValue(newPerson, kABPersonSocialProfileProperty, multiSocial, NULL);
CFRelease(multiSocial);

Where am I going wrong?

解决方案

Setting social profiles is very tricky for some reason, but here is the code necessary to doing so:

ABMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);

ABMultiValueAddValueAndLabel(multiSocial, (__bridge CFTypeRef)([NSDictionary dictionaryWithObjectsAndKeys:(NSString *)kABPersonSocialProfileServiceFacebook, kABPersonSocialProfileServiceKey, theFacebook, kABPersonSocialProfileUsernameKey,nil]), kABPersonSocialProfileServiceFacebook, NULL);

ABRecordSetValue(newPerson, kABPersonSocialProfileProperty, multiSocial, NULL);

According to the documentation, the social profiles is a kABMultiDictionaryPropertyType, not kABMultiStringType.

That also means that you need to add dictionaries to multiSocial, not strings. The format does not make sense to me for the dictionary, so just copy and paste whenever you need to use it.

Then, you set it how you did before.

这篇关于如何在iOS中写Facebook / Twitter来通讯录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆