locked
CNLabeledValue<ValueType> requires 1 type argument RRS feed

  • Question

  • User295088 posted

    Hi, I'm trying to write to contacts using https://developer.xamarin.com/guides/ios/platformfeatures/introductionto_ios9/contacts/ 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[]'. 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.

    Tuesday, February 28, 2017 6:59 PM

Answers

  • User295088 posted

    It has been answered here https://forums.xamarin.com/discussion/comment/256034#Comment_256034

    Thank you @VinayakGawas

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 1, 2017 2:58 PM