1

获取联系人并创建组并使用组 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帮助

预先感谢

4

0 回答 0