Generating Address Book Contacts on iPhone Simulator with MonoTouch
February 1, 2011 Leave a comment
One of the things that I needed for testing my app was a list of contacts to play around with in the Contacts app on the iPhone simulator. The only way to do this is to either manually input contacts — which I am not willing to do for 50+ contacts — or programmatically add them in with a bit of random data.
I have done the latter. Check out the monotouch-generate-contacts project on github. This app, once run on the simulator, will add 50 contacts into the address book and generate some random phone numbers for each contact.
For those of you that don’t care about the project on git hub, here’s the main gist of how you add a contact to the address book.
var addressBook = new ABAddressBook(); var record = new ABPerson(); record.FirstName = "Marco"; record.LastName = "Polo"; var phones = new ABMutableStringMultiValue(); phones.Add("4566545555", ABPersonPhoneLabel.Mobile); record.SetPhones(phones); addressBook.Add(record); addressBook.Save();