3
我正在尝试将联系人添加到iOS8中的地址簿。无法再这样做了。这里是我的代码如下:iOS 8将地址簿添加到地址簿
-(void)addPersonToAddressBook {
NSString * fullName = integrationDictionary[@"fullName"];
ABPeoplePickerNavigationController *pp =[ABPeoplePickerNavigationController new];
ABAddressBookRef addressBook = [pp addressBook];
ABRecordRef entry = ABPersonCreate();
CFErrorRef cfError=nil;
ABRecordSetValue(entry, kABPersonFirstNameProperty, (__bridge CFTypeRef)(fullName) , nil);
ABAddressBookAddRecord(addressBook, entry, &cfError);
if (ABAddressBookSave(addressBook, &cfError)) {
NSString *saveMessage = [NSString stringWithFormat:@"%@ has been added to your address book.", fullName];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact Added" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
} else {
NSString *saveMessage = [NSString stringWithFormat:@"There was an error adding %@ to your address book.", fullName];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uh Oh" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
NSLog(@"error is %@", cfError);
错误显示为空。有没有人见过这个?任何解决方法?
在代码块'''ABAddressBookRequestAccessWithCompletion''' - 你不应该有一个if语句,它检查'' 'BOOL'''的价值,看看用户是否真的授予应用程序访问? – Supertecnoboff 2015-07-30 05:58:53
@Supertecnoboff这只是一个固有缺陷的例子......我已经回答了OP。 – Razvan 2015-07-30 09:02:08