連絡先を取得してグループを作成し、グループ ID を使用して連絡先 inot グループをプッシュすると、ios で失敗する
グループが既に存在するかどうかを確認し、存在しない場合はグループを作成します
-(void) CheckIfGroupExistWithName:(NSString*)groupName {
BOOL hasGroup = NO;
//checks to see if the group is created ad creats group for contacts
// ABAddressBookRef addressBook = ABAddressBookCreate();
CFIndex groupCount = ABAddressBookGetGroupCount(addressBook);
CFArrayRef groupLists= ABAddressBookCopyArrayOfAllGroups(addressBook);
for (int i=0; i<groupCount; i++) {
ABRecordRef currentCheckedGroup = CFArrayGetValueAtIndex(groupLists, i);
NSString *currentGroupName = (__bridge NSString *)ABRecordCopyCompositeName(currentCheckedGroup);
NSLog(@"GroupName= %@",groupName);
if ([currentGroupName isEqualToString:groupName]){
//!!! important - save groupID for later use
groupId = ABRecordGetRecordID(currentCheckedGroup);
NSLog(@"group id = %i",groupId);
hasGroup=YES;
}
}
if (hasGroup==NO){
//id the group does not exist you can create one
[self createNewGroup:groupName];
}
//CFRelease(currentCheckedGroup);
CFRelease(groupLists);
//CFRelease(addressBook);
}
連絡先の詳細を取得し、この方法で保存しようとします
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *name = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
contactNameText.text=name;
ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* mobile=@"";
mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, 0);
contactNoText.text=mobile;
CFErrorRef error=NULL;
addressBook = ABAddressBookCreate();
ABRecordRef ICEBUZZGroup = ABAddressBookGetGroupWithRecordID(addressBook, groupId);
BOOL didAdd = ABGroupAddMember(ICEBUZZGroup,person,&error);
if (!didAdd) {
}
BOOL didSave = ABAddressBookSave(addressBook, &error);
if (!didSave) {
}
PLの助け
少し早いですがお礼を