0
嘗試在我的viewdidload中使用下面的代碼,我似乎無法得到一個測試聯繫人加載到我的測試iphone(運行IOS 6)。任何建議爲什麼這不起作用?IOS 6地址簿
CFErrorRef* error;
// create address book record
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil,error);
// create a person
ABRecordRef person = ABPersonCreate();
// first name of the new person
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil);
// his last name
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil);
//add the new person to the record
ABAddressBookAddRecord(addressBook, person, nil);
ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", error); // set group's name
ABGroupAddMember(group, person, error); // add the person to the group
ABAddressBookAddRecord(addressBook, group, error); // add the group
//save the record
ABAddressBookSave(addressBook, nil);
// relase the ABRecordRef variable
CFRelease(person);
這可能是一個權限問題。請參閱http://stackoverflow.com/questions/12517394/ios-6-address-book-not-working?rq=1 – rmaddy
請參閱http://stackoverflow.com/questions/14018131/iphone-address-book-phone-數字/ 14018453#14018453 –