Skip to content

Instantly share code, notes, and snippets.

@ranmyfriend
Last active August 29, 2015 14:20
Show Gist options
  • Save ranmyfriend/463a3ba8b9aeeb21e2fc to your computer and use it in GitHub Desktop.
Save ranmyfriend/463a3ba8b9aeeb21e2fc to your computer and use it in GitHub Desktop.
contacts filling API
/* Here You can able to fill the 6k contacts to iPhone default AddressBook.
Its for testing purpose only I created this API.
6000 contacts: 1000 (Steve), 1000 (Tim), 1000 (Kalam), 1000 (Jonathan), 1000 (Vishal), (1000) (Zippr)
*/
- (void)dummyContactsFill {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
for(int i=0;i<6000;i++) {
ABRecordRef newPerson = ABPersonCreate();
NSString *firstName;
NSString *lastName;
NSString *organization;
NSString *homeNumber;
NSString *workNumber;
NSString *homeEmail;
NSString *workEmail;
if(i<1000) {
firstName = [NSString stringWithFormat:@"Steve%d",i];
lastName = [NSString stringWithFormat:@"Jobs"];
organization = [NSString stringWithFormat:@"apple.com"];
homeNumber =[NSString stringWithFormat:@"%d328-1111111",i];
workNumber = [NSString stringWithFormat:@"%d02-222222",i];
homeEmail = [NSString stringWithFormat:@"SteveJobs%d@apple.com",i];
workEmail = [NSString stringWithFormat:@"CEO%d@apple.com",i];
}
else if(i<2000) {
firstName = [NSString stringWithFormat:@"Tim%d",i];
lastName = [NSString stringWithFormat:@"Cook"];
organization = [NSString stringWithFormat:@"apple.com"];
homeNumber =[NSString stringWithFormat:@"%d123456789",i];
workNumber = [NSString stringWithFormat:@"%d02-99993622",i];
homeEmail = [NSString stringWithFormat:@"Tim%d@apple.com",i];
workEmail = [NSString stringWithFormat:@"GM%d@apple.com",i];
}
else if(i<3000) {
firstName = [NSString stringWithFormat:@"Abdul%d",i];
lastName = [NSString stringWithFormat:@"Kalam"];
organization = [NSString stringWithFormat:@"Indian.com"];
homeNumber =[NSString stringWithFormat:@"%d9993524210",i];
workNumber = [NSString stringWithFormat:@"%d09-3424211",i];
homeEmail = [NSString stringWithFormat:@"kalam%d@icloud.com",i];
workEmail = [NSString stringWithFormat:@"Sr.Scientist%d@isro.com",i];
}
else if(i<4000) {
firstName = [NSString stringWithFormat:@"Jonathan%d",i];
lastName = [NSString stringWithFormat:@"Ivy"];
organization = [NSString stringWithFormat:@"apple.com"];
homeNumber =[NSString stringWithFormat:@"%d333-44444",i];
workNumber = [NSString stringWithFormat:@"%d07-6969696",i];
homeEmail = [NSString stringWithFormat:@"Ive%d@apple.com",i];
workEmail = [NSString stringWithFormat:@"Sr.DesignEngineer%d@apple.com",i];
}
else if (i<5000) {
firstName = [NSString stringWithFormat:@"Vishal%d",i];
lastName = [NSString stringWithFormat:@"Nalimela"];
organization = [NSString stringWithFormat:@"zippr.in"];
homeNumber =[NSString stringWithFormat:@"%d5555-777",i];
workNumber = [NSString stringWithFormat:@"%d001-92929292",i];
homeEmail = [NSString stringWithFormat:@"Vishal%d@zippr.in",i];
workEmail = [NSString stringWithFormat:@"QALead%d@zippr.in",i];
}
else {
firstName = [NSString stringWithFormat:@"Zippr%d",i];
lastName = [NSString stringWithFormat:@"Pvt. Ltd"];
organization = [NSString stringWithFormat:@"zippr.in"];
homeNumber =[NSString stringWithFormat:@"%d00099999",i];
workNumber = [NSString stringWithFormat:@"%d01-78787878",i];
homeEmail = [NSString stringWithFormat:@"zipprCare%d@zippr.in",i];
workEmail = [NSString stringWithFormat:@"care%d@zippr.com",i];
}
// add personal details
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFTypeRef)firstName, nil);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, (__bridge CFTypeRef)lastName, nil);
ABRecordSetValue(newPerson, kABPersonOrganizationProperty, (__bridge CFTypeRef)organization, nil);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)homeNumber, kABHomeLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone,(__bridge CFTypeRef)workNumber, kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail,(__bridge CFTypeRef)homeEmail, kABHomeLabel, NULL);
ABMultiValueAddValueAndLabel(multiEmail,(__bridge CFTypeRef)workEmail,kABWorkLabel,NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, nil);
CFRelease(multiEmail);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, nil);
BOOL didAdd = ABAddressBookSave(iPhoneAddressBook, nil);
if(didAdd) {
NSLog(@"successfully added %dth contact",i);
}
CFRelease(newPerson);
}
CFRelease(iPhoneAddressBook);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment