public void GetUnifiedContacts() { string identifier = null; TestRuntime.CheckContactsPermission(); var fetchKeys = new [] { CNContactKey.Identifier, CNContactKey.GivenName, CNContactKey.FamilyName }; NSError error; using (var predicate = CNContact.GetPredicateForContacts("Appleseed")) using (var store = new CNContactStore()) { var contacts = store.GetUnifiedContacts(predicate, fetchKeys, out error); // we can't be sure what's on devices, so check there's no error is the only thing we do Assert.Null(error, "error"); // but it's in the default simulator build (but not the watchOS simulator) #if !__WATCHOS__ && !MONOMAC if (Runtime.Arch == Arch.SIMULATOR) { Assert.That(contacts.Length, Is.EqualTo(1), "Length"); identifier = contacts [0].Identifier; } #endif } // if we can't find the previous contact then we don't have an identifier for the GetUnifiedContact API // and we can't hardcode one as each simulator instance has a different identifier... if (identifier == null) { return; } using (var store = new CNContactStore()) { var contact = store.GetUnifiedContact(identifier, fetchKeys, out error); // it's in the default simulator build #if !MONOMAC if (Runtime.Arch == Arch.SIMULATOR) { Assert.Null(error, "error"); Assert.NotNull(contact, "contact"); Assert.False(contact.AreKeysAvailable(CNContactOptions.OrganizationName | CNContactOptions.Note), "AreKeysAvailable-1"); Assert.True(contact.AreKeysAvailable(CNContactOptions.None), "AreKeysAvailable-2"); Assert.True(contact.AreKeysAvailable(fetchKeys), "AreKeysAvailable-3"); } else { #endif // and it's a safe bet that id does not exists on any device Assert.NotNull(error, "error"); // Updated Record Does Not Exist #if !MONOMAC } #endif } }
public void GetUnifiedContacts() { string identifier = null; TestRuntime.CheckContactsPermission(); var fetchKeys = new [] { CNContactKey.Identifier, CNContactKey.GivenName, CNContactKey.FamilyName }; NSError error; using (var predicate = CNContact.GetPredicateForContacts("Appleseed")) using (var store = new CNContactStore()) { var contacts = store.GetUnifiedContacts(predicate, fetchKeys, out error); // we can't be sure what's on devices, so check there's no error is the only thing we do // but it's in the default simulator build (but not the watchOS simulator) #if !MONOMAC && !__WATCHOS__ && !__MACCATALYST__ if ((error == null) && (Runtime.Arch == Arch.SIMULATOR)) { Assert.That(contacts.Length, Is.EqualTo(1), "Length"); identifier = contacts [0].Identifier; } #endif } // if we can't find the previous contact then we don't have an identifier for the GetUnifiedContact API // and we can't hardcode one as each simulator instance has a different identifier... if (identifier == null) { return; } using (var store = new CNContactStore()) { var contact = store.GetUnifiedContact(identifier, fetchKeys, out error); // it's in the default simulator build if (TestRuntime.IsSimulatorOrDesktop) { // it fails on some bots (watchOS 4.2 on jenkins) so we cannot assume it always work if (error != null) { return; } Assert.NotNull(contact, "contact"); Assert.False(contact.AreKeysAvailable(CNContactOptions.OrganizationName | CNContactOptions.Note), "AreKeysAvailable-1"); Assert.True(contact.AreKeysAvailable(CNContactOptions.None), "AreKeysAvailable-2"); Assert.True(contact.AreKeysAvailable(fetchKeys), "AreKeysAvailable-3"); } } }