Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24359] iOS: Can not add number to the contact list using setPhone method.

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2017-01-31T19:35:52.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterMotiur Rahman
AssigneeHans Knöchel
Created2017-01-31T18:42:14.000+0000
Updated2017-03-24T18:04:06.000+0000

Description

Description

Can not add the phone number to the contact list using [setPhone](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Contacts.Person-method-setPhone) method.

Steps To Reproduce

1. Just run the following code to the device. 2. Click the add button then check the phone contact.
var win = Titanium.UI.createWindow({
	title : 'Add Phone',
	backgroundColor : '#fff',
	layout : 'vertical'
});

// Create a Button.
var add = Ti.UI.createButton({
	title : 'Add Number',
	height : Ti.UI.SIZE,
	width : Ti.UI.SIZE,
	top : 50,

});

var person = Ti.Contacts.createPerson({
	firstName : 'fname',
	lastName : 'lname',

});

// Listen for click events.
add.addEventListener('click', function() {

	var number = {
		phone : {
			mobile : ['01723306519']

		}
	};

	person.setPhone(number);

	Ti.API.info('Contact saved');
});

// Add to the parent view.
win.add(add);

win.open();

[ERROR] :  Script Error {
[ERROR] :      column = 17;
[ERROR] :      line = 32;
[ERROR] :      message = "*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray";
[ERROR] :      stack = "[native code]\n";
[ERROR] :  }

Comments

  1. Hans Knöchel 2017-01-31

    The "phone" argument should be set when creating the person, I don't think the (manual) setters should even be in the docs. Better:
       Ti.Contacts.createPerson({
           firstName: 'Hans',
           lastName: 'Knoechel',
           phone: {
               mobile: ['+49 1723306519'],
           }
       });
       
    Please give it a try. *EDIT*: And for the case it has to be added to an existing contact, we'd need to investigate it.
  2. Hans Knöchel 2017-01-31

    This ticket is invalid. The "phone" key should not be there of course, you are already specifying the property to set in the setter. Working code:
       var win = Titanium.UI.createWindow({
       	title : 'Add Phone',
       	backgroundColor : '#fff',
       	layout : 'vertical'
       });
        
       // Create a Button.
       var add = Ti.UI.createButton({
       	title : 'Add Number',
       	height : Ti.UI.SIZE,
       	width : Ti.UI.SIZE,
       	top : 50,
        
       });
        
       var person = Ti.Contacts.createPerson({
       	firstName : 'fname',
       	lastName : 'lname',
        
       });
        
       // Listen for click events.
       add.addEventListener('click', function() {
        
       	var number = {
       		mobile : ['01723306519'] 
       	};
        
       	person.setPhone(number);
        
       	Ti.API.info('Contact saved');
       });
        
       // Add to the parent view.
       win.add(add);
        
       win.open();
       
  3. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source