gpt4 book ai didi

iphone - iOS 地址簿谓词

转载 作者:行者123 更新时间:2023-11-29 13:24:01 25 4
gpt4 key购买 nike

我得到地址簿中所有联系人的数组:

  NSMutableArray *records = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople( addressBook );

对于联系人的名字,谓词应采用什么格式?我已经按照这个问题中的建议尝试了 record.:Search ABAddressbook iOS SDK但我得到一个未知的关键异常。数组中的项目似乎是 __NSCFType 类型。任何帮助将不胜感激。

最佳答案

嘿,要从设备获取联系信息,您还可以将我的波纹管代码与我创建的 Contact bean 类一起使用,请看这里..

还需要包含 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 是下面的 NObject (Bean) 文件

@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

希望对你有帮助...

关于iphone - iOS 地址簿谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13625580/

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