如何使用monotouch将联系人添加到iPhone地址簿?

时间:2011-01-27 20:46:05

标签: iphone xamarin.ios

我需要能够在monotouch中访问地址簿,并在我的项目中添加/修改/删除。我该怎么做?

2 个答案:

答案 0 :(得分:7)

使用ABAddressBook。以下是添加名称,地址和电话的新联系人的示例

        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();

答案 1 :(得分:4)

对于任何有兴趣的人,我已经创建了一个示例项目,用于使用随机电话号码在地址簿中输入联系人。希望这有助于其他人。

https://github.com/ayoung/monotouch-generate-contacts

相关问题