【发布时间】:2019-12-14 03:08:30
【问题描述】:
我正在使用 Xamarin.iOS 开发的一个小应用程序出现问题
我的目标只是让每个联系人都出现在 iPhone 上。
我有这个代码,到目前为止它在我的手机和至少 3 个其他人上都有效。 昨天我在我的配置文件中添加了一个人,因为当我尝试获取容器时,我无法在手机上获得除“null”之外的任何其他值。
我的手机是 iPhone 7 iOS 13.1.2 - 我无法在任何其他手机上测试它。
它仍然可以在模拟器上运行(iPhone 8 iOS 13.1)。
我的 info.plist 中有联系授权请求。 我只是不明白获取默认容器时获取“null”是什么意思......
try
{
var keysTOFetch = new[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.Nickname, CNContactKey.JobTitle, CNContactKey.DepartmentName, CNContactKey.OrganizationName, CNContactKey.PostalAddresses, CNContactKey.UrlAddresses, CNContactKey.EmailAddresses, CNContactKey.PhoneNumbers };
NSError error;
CNContact[] contactList;
var ContainerId = new CNContactStore().DefaultContainerIdentifier; <---- //This where I get a null I never got before ...
if (ContainerId != null)
{
using (var predicate = CNContact.GetPredicateForContactsInContainer(ContainerId))
using (var store = new CNContactStore())
contactList = store.GetUnifiedContacts(predicate, keysTOFetch, out error);
var contacts = new List<UserContact>();
status = writeCSV(contactList, user);
}
else
Console.WriteLine("Didn't get any container identifier ..");
}
Apple 文档说它可以返回 'null' 但没有进一步解释 ..
非常感谢您的帮助
【问题讨论】:
标签: c# ios iphone xamarin.ios