I need to be able to access the address book in monotouch and add/modify/delete from there within my project. How would I do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use ABAddressBook. Here's an example of adding a new contact with a name, address and phone
ABAddressBook ab = new ABAddressBook();
ABPerson p = new ABPerson();
p.FirstName = fname;
p.LastName = lname;
ABMutableMultiValue<string> phones = new ABMutableStringMultiValue();
phones.Add(phone, ABPersonPhoneLabel.Mobile);
p.SetPhones(phones);
ABMutableDictionaryMultiValue addresses = new ABMutableDictionaryMultiValue();
NSMutableDictionary a = new NSMutableDictionary();
a.Add(new NSString(ABPersonAddressKey.City), new NSString(city));
a.Add(new NSString(ABPersonAddressKey.State), new NSString(state));
a.Add(new NSString(ABPersonAddressKey.Zip), new NSString(zip));
a.Add(new NSString(ABPersonAddressKey.Street), new NSString(addr1));
addresses.Add(a, new NSString("Home"));
p.SetAddresses(addresses);
ab.Add(p);
ab.Save();
回答2:
For anyone interested, I have created a sample project for inputing contacts in the address book with random phone numbers. Hope this helps other people.
https://github.com/ayoung/monotouch-generate-contacts