I need to insert 25000 contacts to iPhone contacts as far as I coded it works fine on simulator and this can be achieved in few minutes. But when I import this on a iPhone 4s it takes more than 3 hours and also only partial contacts gets saved and then app gets closed.
Help me with a easy way to insert multiple records to address book...
Here is my piece of code...
for (int i = 0; i < [contactNameArray count]; i++) {
//Create new person and save to this group
ABRecordRef record = ABPersonCreate();
BOOL isSuccess ;
NSString *firstname = [NSString stringWithFormat:@"%@",[contactNameArray objectAtIndex:i]];
isSuccess = ABRecordSetValue(record, kABPersonFirstNameProperty,(__bridge CFStringRef)firstname, &error);
isSuccess = ABRecordSetValue(record, kABPersonLastNameProperty,CFSTR("Custom Contacts"), &error);
ABMutableMultiValueRef copyOfPhones = ABMultiValueCreateMutable(kABPersonPhoneProperty);
NSString *phonenumber = [NSString stringWithFormat:@"%@",[contactPhoneArray objectAtIndex:i]];
CFTypeRef phone= (__bridge CFStringRef)phonenumber;
ABMultiValueAddValueAndLabel(copyOfPhones, phone,kABPersonPhoneMobileLabel,NULL);
isSuccess = ABRecordSetValue(record, kABPersonPhoneProperty, copyOfPhones, &error);
CFRelease(copyOfPhones);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
NSString *emailid = [NSString stringWithFormat:@"%@",[contactEmailArray objectAtIndex:i]];
CFTypeRef email= (__bridge CFStringRef)emailid;
ABMultiValueAddValueAndLabel(multiEmail, email, kABWorkLabel, NULL);
ABRecordSetValue(record, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
isSuccess = ABAddressBookAddRecord(ab, record, &error);
isSuccess = ABAddressBookSave(ab, &error);
ABGroupAddMember(group, record, &error);
NSLog(@"is success %d", isSuccess);
ABAddressBookSave(ab, &error);
}
Thanks in advance....