Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20407] Ti.Contacts.save() unresponsive on iOS>=9

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2016-04-05T06:24:14.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.4.0
Componentsn/a
Labelsios, qe-.5.4.0
ReporterRhys Leo Coronado
AssigneeSrikanth Sombhatla
Created2016-02-15T15:02:48.000+0000
Updated2016-06-09T22:31:29.000+0000

Description

Hi, I'm trying to use Ti.Contacts.save() in iOS>=9, but it seems unresponsive or isn't saving at all. I get this kind of error when trying to use methods like Ti.Contacts.Person (object).setPhone() {"message":"-\[CNContact setPhoneNumbers:\]: unrecognized selector sent to instance 0x7fb6b34d5980") We're using the default or unmodified TiContactsPerson.m
var win = Ti.UI.createWindow({
	backgroundColor: '#ffffff'
});


var button = Ti.UI.createButton({
	width: 200,
	height: 50,
	title: "Save to address book"
});

win.add(button);


function performAddressBookFunction() {
	// sample stopped working on 5.1.2.GA
	// var people = Ti.Contacts.getAllPeople();
	// var contactsToSave = [];
// 	
	// for (var i=0; i<people.length; i++) {
		// contactsToSave.push(people[i]);
		// Ti.Contacts.removePerson(people[i]);
	// }
// 	
	// Ti.Contacts.save(contactsToSave);
	// contactsToSave = [];
	
	Ti.Contacts.createPerson({
	  	firstName: 'Rey',
	  	lastName: 'Bumalay',	
	  	phone: {
	  		mobile: ['+63 9176490093', '+63 9176490094'],
	  		'Toll Free': ['1 800 1000000']
	  	},
	  	email: {
	  		work: ['john@doe.com'],
	  		'Personal Email': ['reyjexter@gmail.com']
	  	},
	 	url: {
	  		homepage: ['http://www.google.com'],
	  		'Resume/CV/BIO': ['http://www.myresume.com'],
	  		'Schedule as a Service': ['http://www.service.com']
	  	}
	});
	
	alert("Successfully saved");
}

function addressBookDisallowed() {
	alert("Address book disallowed");
}
	

button.addEventListener('click', function(e) {
	
	if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
	    performAddressBookFunction();
	} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
	    Ti.Contacts.requestAuthorization(function(e){
	        if (e.success) {
	            performAddressBookFunction();
	        } else {
	            addressBookDisallowed();
	        }
	    });
	} else {
	    addressBookDisallowed();
	}
});

win.open();

Comments

  1. Rhys Leo Coronado 2016-02-15

    To add: {"message":"-[CNContact setPhoneNumbers:]: unrecognized selector sent to instance 0x7fb6b34d5980") ^It happens with setEmail(), setUrl(), setAddress(), setInstantMessage with their respective error setEmail, setUrl, setAddress, setInstantMessage unrecognized selector sent to instance.
  2. Chee Kiat Ng 2016-02-16

    This may already be fixed in 5.2.0. [~ssombhatla] check it out?
  3. Srikanth Sombhatla 2016-02-23

    [~rlcoronado] We currently don't support custom labels like Toll Free,Personal Email. For example the supported labels for phone are https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Contacts.Person-property-phone
  4. Dustin Hume 2016-02-27

    This is still an issue in 5.2.0 and it is not related to the customer labels mentioned.
       var currentAddress = f.person.address;
       if(currentAddress.work){
           var addressAlreadyExists = false;
           for(var i=0;i<currentAddress.work.length;i++){
               if(currentAddress.work[i].Street == contactInfo.location){
                   addressAlreadyExists = true;
               }
           }
           if(!addressAlreadyExists){
               currentAddress.work.push({
                   CountryCode: 'us',
                   Street: contactInfo.location
               });
           }
           addressAlreadyExists=null;
       }
       else{
           currentAddress.work = [{
               CountryCode: 'us',
               Street: contactInfo.location
           }];
       }
       f.person.setAddress(currentAddress);
       currentAddress=null;
       
    f.person.setAddress(currentAddress) throws this error:
       [ERROR] Script Error {
           column = 25;
           line = 788;
           message = "-[CNContact setPostalAddresses:]: unrecognized selector sent to instance 0x7ff15bba7590";
       
    In addition, as mentioned, setPhone(), setEmail(), and setUrl() also throw a similar error. This same code works fine in iOS versions below 9
  5. Srikanth Sombhatla 2016-02-29

    Reopened for validation.
  6. Srikanth Sombhatla 2016-04-05

  7. Harry Bryant 2016-06-09

JSON Source