我得到的地址簿中,这样所有的接触点阵列:的iOS地址簿谓词
NSMutableArray *records = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
什么格式将谓词是在说一个联系人的名字?我已经试过的记录。在这个问题中建议:Search ABAddressbook iOS SDK但我得到一个未知的关键异常。数组中的项似乎为__NSCFType类型。任何帮助将不胜感激。
我得到的地址簿中,这样所有的接触点阵列:的iOS地址簿谓词
NSMutableArray *records = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
什么格式将谓词是在说一个联系人的名字?我已经试过的记录。在这个问题中建议:Search ABAddressbook iOS SDK但我得到一个未知的关键异常。数组中的项似乎为__NSCFType类型。任何帮助将不胜感激。
哎从设备获取联系人信息,你也可以使用我的波纹管代码联系豆类创建只是看到这个..
你也需要包括AddressBook.framework
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABPerson.h>
[contactList removeAllObjects];
// open the default address book.
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
NSLog(@"opening address book");
}
// can be cast to NSArray, toll-free
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
// CFStrings can be cast to NSString!
for (int i=0;i < nPeople;i++) {
MContact *contact = [[MContact alloc] init];
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
CFStringRef firstName, lastName;
firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
contact.name = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
ABMutableMultiValueRef eMail = ABRecordCopyValue(ref, kABPersonEmailProperty);
if(ABMultiValueGetCount(eMail) > 0) {
contact.email = (NSString *)ABMultiValueCopyValueAtIndex(eMail, 0);
[contactList addObject:contact];
}
CFRelease(ref);
CFRelease(firstName);
CFRelease(lastName);
}
和这里MContact是波纹管
@interface MContact : NSObject {
NSString *email;
NSString *name;
NSString *lastName;
NSString *phone;
BOOL isSelected;
}
@property (nonatomic, retain) NSString *email;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *lastName;
@property (nonatomic, retain) NSString *phone;
@property (nonatomic) BOOL isSelected;
@property (nonatomic, readonly) NSString *displayName;
@end
我希望这会帮助你n对象(Bean)的文件......
马里奥看看下面的代码。我测试过了,它工作正常。
// Retrieving the address from address book...
ABAddressBookRef ref = ABAddressBookCreate();
CFArrayRef getArr = ABAddressBookCopyArrayOfAllPeople(ref);
CFIndex totCount = CFArrayGetCount(getArr);
for (int m = 0; m < totCount; m++)
{
ABRecordRef recordRef = CFArrayGetValueAtIndex(getArr, m);
ABMultiValueRef names = ABRecordCopyValue(recordRef, kABPersonPhoneProperty);
NSString* getFirstName = (__bridge NSString *)names;
NSLog(@"The name is :-%@\n", getFirstName);
getFirstName = (__bridge NSString*)ABMultiValueCopyValueAtIndex(names, 1);
NSLog(@"The phone number is :-%@\n", getFirstName);
}
如有任何问题,请回复我。
嗨感谢,我的问题是如何将应用谓词的getArr –
不能我们NSPredicates与ABAddressBook –
嘿马里奥,如果你想使用NSPredicate,那么你需要首先投CFArrayRef来NSMutableArray/NSArray,因为CFArrayRef是免费的网桥,所以你可以实现它:一个CFArrayRef免费桥接到NSArray *,所以你可以把它转换为这样,然后创建一个可变副本: NSMutableArray * convertedData =( __bridge NSArray *)getArr mutableCopy];然后,您可以像使用NSArray一样使用NSPredicate。希望,这是你需要的。 :) –