Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iPhone Create Contact

Hey guys,

i currently am unable to create a contact within my iPhone app.

This is the code i use.

var contact = Titanium.Contacts.createPerson();
contact.firstName = companyname+' - ';
contact.lastName = shortcutname;
contact.note = shortcut;
Titanium.Contacts.save();
});

This adds a contact fine, but as soon as i add "contact.phone" the app crashes.

Anyone know the reason why?

-Tom

— asked July 23rd 2010 by Thomas Shurrock
  • contact
  • crash
  • iphone
0 Comments

3 Answers

  • try

    contact.phone = {'work':[PHONEP],'workFax':[FAX],'mobile':[CELL]};

    — answered August 3rd 2010 by Andreas Schauer
    permalink
    0 Comments
  • Thats awesome, got it working now fine!

    Is there anyway of setting an ID of a contact, so i can check within the app if the contact has already been added or not, to stop duplicates!

    Thanks

    — answered August 3rd 2010 by Thomas Shurrock
    permalink
    1 Comment
    • How it worked can you tell I am also facing this issue. Although its 3 years before asked question.

      — commented February 21st 2013 by Nabeel Munawar
  • Ok, here my structure in iOS, after caling the app crashes:

    var contact = Ti.Contacts.createPerson({
        URL : {
            "homepage" : 'http://vladi.de'
        },
        phone : {
            "work" : ['004940330000']
        },
        email : {
            "work" : ['info@vladi.de']
        },
        lastName : 'Vladi Private Islands',
        kind : Ti.Contacts.CONTACTS_KIND_ORGANIZATION,
        address : {
            "work" : {
                "Street" : 'Ballindamm 7',
                "City" : 'Hamburg',
                "State" : 'Hamburg',
                "ZIP" : '2000'
            }
        }
    });
    

    with -[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa0885b0

    Whats going wrong?

    — answered October 25th 2011 by Rainer Schleevoigt
    permalink
    3 Comments
    • I have the same problem. Either in iPhone Simulator or iPhone device this is crashing my application with this error message (Simulator): "-[KrollCallback countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x8d87820" It creates only a blank contact on iPhone.

      — commented October 28th 2011 by Benjamin Philipp
    • I am having the same @Rainder did you find any solution?? please provide.
      I am using the following code to create contact. App crashes contacts are saved properly but app crashes. why? any solution?

      var contact = Titanium.Contacts.createPerson();
                      contact.firstName = cat_name;
                      contact.organization = cat_organization;
                      contact.kind = Titanium.Contacts.CONTACTS_KIND_ORGANIZATION;
                      var address = {};
                      address.Street = cat_addr;
                      address.City = cat_city;
                      address.State = cat_state;
                      address.ZIP = cat_zip;
      
                      contact.address = {"work":[address]};   
                      contact.email = {"work": [cat_email]};
                      contact.phone  = {"work": [cat_phone]};
      
                      Titanium.Contacts.save(contact);
      
                      Titanium.UI.createAlertDialog({ 
                          title:'Contact added',
                      }).show();
      

      — commented February 21st 2013 by Nabeel Munawar
    • Hi Everyone,

      i am facing the same issue Rainer faced above , have anybody solved this issue, pls i need help i am using below code to add contact

      var contact = {
              "organization" : e.data.fieldByName("name"),
              "address" : {
                  "work" : [{
                      "CountryCode" : e.data.fieldByName("countryCode"),
                      "Street" : e.data.fieldByName("street"),
                      "City" : e.data.fieldByName("city"),
                      "County" : "", ,
                      "State" : "", ,
                      "Country" : e.data.fieldByName("country"),
                      "ZIP" : e.data.fieldByName("zip")
                  }]
              },
              "phone" : {
                  "work" : ["1234567890"]
              }
          };
      
      Ti.Contacts.createPerson(contact);
      

      i need suggestion , if i am doing something wrong..

      — commented March 22nd 2014 by Sagar Patel
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.