2011-03-29 58 views
1

如何使用MonoTouch c#从iPhone联系人获取手机号码和工作号码?我用这个代码,如何使用MonoTouch从iPhone通讯录中获取手机号码和工作号码?

ABMultiValue<String> phoneMV = person.GetPhones(); 
String[] phoneval = phoneMV.GetValues(); 
for(int i = 0; i< phoneval.Length; i++) { 
Console.WriteLine(phoneval[i]); 
} 

但它打印联系人号码的所有值。如何从联系人获取特定属性?例如,我需要手机和工作号码,家庭和工作电子邮件ID。我不想要所有的价值。如何实现这一目标?

回答

3

ABMultiValue<T>ABMultiValueEntry<T>值的集合。电话号码(工作,家庭等)的类型存储在ABMultiValueEntry<T>.Label属性中,您可以与之比较。 ABLabel.Work

IEnumerable<ABMultiValueEntry<string>> workPhoneEntries = person.GetPhones() 
     .Where(p => p.Label == ABLabel.Work); 
IEnumerable<string> workNumbers = workPhoneEntries.Select(p => p.Value); 
+0

如何从联系人获取地址?我从接触中获得了所有的价值。但我不能得到地址。 – bharath 2011-04-06 07:56:33

+0

地址是相同的,只是不同的; ABPerson.GetAddresses()返回(有效)'IEnumerable >',类似于ABPerson.GetPhones(),因此请检查“ABMultiValueEntry .Label”作为“正确”地址(工作,家庭等)。 )。 'ABMultiValueEntry .Value'包含地址,其中密钥是地址部分,值是地址值;请参阅:http://www.go-mono.com/docs/index.aspx?link=T%3aMonoTouch.AddressBook.ABPersonAddressKey – jonp 2011-04-06 20:24:03

相关问题