Forum Xamarin.iOS

CNLabeledValue<ValueType> requires 1 type argument

DeviOSDeviOS USMember ✭✭

I'm trying to write to contacts using
I'm getting an error on CNLabeledValue when I'm trying to add a phone number. Error: Using the generic type Contacts.CNLabeledValue<ValueType>' requires1' type argument(s)

And also on contact.PhoneNumbers = new NSObject[] { cellPhone, workPhone }; Error: Cannot implicitly convert type Foundation.NSObject[]' toContacts.CNLabeledValue<Contacts.CNPhoneNumber>[]'. An explicit conversion exists (are you missing a cast?)

Here's my code:

            public void AddContactMethod(string name, string phone, string email)

                var contact = new CNMutableContact();
                contact.GivenName = name;

                var cellPhone = new CNLabeledValue(CNLabelPhoneNumberKey.iPhone, new CNPhoneNumber("713-555-1212"));
                var workPhone = new CNLabeledValue(CNLabelKey.Work,  new CNPhoneNumber(phone));
                contact.PhoneNumbers = new NSObject[] { cellPhone, workPhone };

                var store = new CNContactStore();
                var saveRequest = new CNSaveRequest();
                saveRequest.AddContact(contact, store.DefaultContainerIdentifier);
                NSError error;
                if (store.ExecuteSaveRequest(saveRequest, out error))
                    Console.WriteLine("New contact saved");
                else {
                    Console.WriteLine("save error {0}", error);

Any help would be appreciated.

Best Answer


Sign In or Register to comment.