Skip to content

Instantly share code, notes, and snippets.

@BohdanOrlov
Created July 15, 2016 12:59
Show Gist options
  • Save BohdanOrlov/4d0705f4550b2192fe30952b6c0b85a8 to your computer and use it in GitHub Desktop.
Save BohdanOrlov/4d0705f4550b2192fe30952b6c0b85a8 to your computer and use it in GitHub Desktop.
Generate contacts with uk phone numbers
@import AddressBook;
- (void)removeContactWithName:(NSString *)name {
NSString *searchName = name;
ABAddressBookRef addressbook = ABAddressBookCreate();
CFStringRef nameRef = (__bridge CFStringRef) searchName;
CFArrayRef allSearchRecords = ABAddressBookCopyPeopleWithName(addressbook, nameRef);
[self removeContactWithRecordsList:allSearchRecords];
}
-(void) removeContactWithRecordsList:(CFArrayRef) selectedRecords_ {
ABAddressBookRef addressbook = ABAddressBookCreate();
if (selectedRecords_ != NULL)
{
long count = CFArrayGetCount(selectedRecords_);
for (long i = 0; i < count; ++i)
{
ABRecordRef contact = CFArrayGetValueAtIndex(selectedRecords_, i);
ABAddressBookRemoveRecord(addressbook, contact, nil);
}
}
ABAddressBookSave(addressbook, nil);
CFRelease(addressbook);
}
- (void)addContacts {
NSArray *numbers = @[@4,@5,@6,@7,@8,@9];
CFErrorRef error = NULL;
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL);
if (error != NULL)
{
CFStringRef errorDesc = CFErrorCopyDescription(error);
NSLog(@"Contact not saved: %@", errorDesc);
CFRelease(errorDesc);
}
for (int i = 0; i < 10000; i++) {
NSString *name = [NSString stringWithFormat:@"Яя-Револют%d", i];
NSString *phoneNumber = [NSString stringWithFormat:@"07%d%d", [numbers[arc4random()%numbers.count] intValue], arc4random()%100000000];
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFTypeRef)(name), &error);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(phoneNumber), kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
// ...
// Set other properties
// ...
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
CFRelease(newPerson);
}
ABAddressBookSave(iPhoneAddressBook, &error);
CFRelease(iPhoneAddressBook);
}
- (void)removeContacts {
[self removeContactWithName:@"Яя-Револют"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment