Obtaining Specific ABSource from ABAddressBook in iOS 4+(在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource)
问题描述
有没有人举例说明如何在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource?
Does anyone have an example of how to obtain a specific ABSource from the ABAddressBook in iOS 4+?
推荐答案
iOS 4+ 提供了新的 API,允许从 ABAddressBook 中选择特定的 ABSource.这可能对某些操作有用,例如某些来源(例如 Exchange)不支持创建 ABGroup.
iOS 4+ provides new API that allows one to select a specific ABSource from the ABAddressBook. This may be useful as some operations, e.g. creating an ABGroup, are not supported in some sources (i.e. Exchange).
并非所有源类型都支持组,更明显的是,Exchange 对组一无所知."- http://flavors.me/volonbolon#1a5/tumblr
"Not all source types support groups, more conspicuously, Exchange does not know anything about groups." - http://flavors.me/volonbolon#1a5/tumblr
附加的是利用新 API 获取特定类型源的函数,这些源可用于调用 ABGroupCreateInSource().
Attached are functions that leverage the new API to obtain sources of specific types which may be used in calls to ABGroupCreateInSource().
#define CFRELEASE_AND_NIL(x) CFRelease(x); x=nil;
ABRecordRef sourceWithType (ABSourceType mySourceType)
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
CFIndex sourceCount = CFArrayGetCount(sources);
ABRecordRef resultSource = NULL;
for (CFIndex i = 0 ; i < sourceCount; i++) {
ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);
BOOL isMatch = mySourceType == [(NSNumber *)sourceType intValue];
CFRELEASE_AND_NIL(sourceType);
if (isMatch) {
resultSource = currentSource;
break;
}
}
CFRELEASE_AND_NIL(addressBook);
CFRELEASE_AND_NIL(sources);
return resultSource;
}
ABRecordRef localSource()
{
return sourceWithType(kABSourceTypeLocal);
}
ABRecordRef exchangeSource()
{
return sourceWithType(kABSourceTypeExchange);
}
ABRecordRef mobileMeSource()
{
return sourceWithType(kABSourceTypeMobileMe);
}
这篇关于在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
