use*_*758 12 objective-c abaddressbook ios7
我正在创建一个将联系人保存到地址簿的应用程序,但是当我将ABAddressBookCreate用于我的代码时,它会显示为警告.我在iOS 7编码.
我的问题是,iOS 7中ABAddressBookCreate的替代品是什么.
任何帮助将不胜感激.谢谢.
Dim*_*ima 35
请ABAddressBookCreateWithOptions()改用.
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
Run Code Online (Sandbox Code Playgroud)
有关此处文档中使用情况的更多信息
编辑
在iOS 9中不推荐使用AddressBook框架,并将其替换为新的和改进的Contacts框架:https://developer.apple.com/library/ios/documentation/Contacts/Reference/Contacts_Framework/index.html#//apple_ref/doc/ UID/TP40015328
在iOS9中联系框架工作:你能看到以下代码吗?
-(void)contactsFromAddressBook{
//ios 9+
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES) {
//keys with fetching properties
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
if (error) {
NSLog(@"error fetching contacts %@", error);
} else {
NSString *phone;
NSString *fullName;
NSString *firstName;
NSString *lastName;
UIImage *profileImage;
NSMutableArray *contactNumbersArray;
for (CNContact *contact in cnContacts) {
// copy data to my custom Contacts class.
firstName = contact.givenName;
lastName = contact.familyName;
if (lastName == nil) {
fullName=[NSString stringWithFormat:@"%@",firstName];
}else if (firstName == nil){
fullName=[NSString stringWithFormat:@"%@",lastName];
}
else{
fullName=[NSString stringWithFormat:@"%@ %@",firstName,lastName];
}
UIImage *image = [UIImage imageWithData:contact.imageData];
if (image != nil) {
profileImage = image;
}else{
profileImage = [UIImage imageNamed:@"person-icon.png"];
}
for (CNLabeledValue *label in contact.phoneNumbers) {
phone = [label.value stringValue];
if ([phone length] > 0) {
[contactNumbersArray addObject:phone];
}
}
NSDictionary* personDict = [[NSDictionary alloc] initWithObjectsAndKeys: fullName,@"fullName",profileImage,@"userImage",phone,@"PhoneNumbers", nil];
[self.contactsArray addObject:personDict];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableViewRef reloadData];
});
}
}
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10307 次 |
| 最近记录: |