I have a Xamarin.Forms App where I like to open the Add Contact Screen. I used the Depedency Service to do this. It works fine on Android but every time I run it on my iPhone, it crashes. My sample code is below.
public bool SaveContactAsync(Profile ContactToSave)
{
var store = new CNContactStore();
var contact = new CNMutableContact();
var cellPhone = new CNLabeledValue<CNPhoneNumber>(CNLabelPhoneNumberKey.Mobile, new CNPhoneNumber(ContactToSave.PhoneNumber));
var phoneNumber = new[] { cellPhone };
contact.PhoneNumbers = phoneNumber;
contact.GivenName = ContactToSave.FirstName;
contact.FamilyName = ContactToSave.LastName;
var emailAddress = new CNLabeledValue<NSString>(CNLabelKey.Other, new NSString(ContactToSave.EmailAddress));
contact.EmailAddresses = new CNLabeledValue<NSString>[] { emailAddress };
var saveRequest = new CNSaveRequest();
saveRequest.AddContact(contact, store.DefaultContainerIdentifier);
NSError error;
if (store.ExecuteSaveRequest(saveRequest, out error))
{
return true;
}
else
{
return false;
}
}
The application crashes once it get to saveRequest.AddContact(contact, store.DefaultContainerIdentifier);
. What could I be doing wrong?
I looked at the App Center Diagnostics, here's what I saw.
libsystem_kernel.dylib
__abort_with_payload
libsystem_kernel.dylib
abort_with_payload
TCC
__CRASHING_DUE_TO_PRIVACY_VIOLATION__
TCC
__TCCAccessRequest_block_invoke.124
TCC
__tccd_send_message_block_invoke
libxpc.dylib
_xpc_connection_reply_callout
libxpc.dylib
_xpc_connection_call_reply_async
libdispatch.dylib
_dispatch_client_callout3
libdispatch.dylib
_dispatch_mach_msg_async_reply_invoke$VARIANT$mp
libdispatch.dylib
_dispatch_kevent_worker_thread
libsystem_pthread.dylib
_pthread_wqthread
libsystem_pthread.dylib
start_wqthread