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