Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20013] iOS8: Ti.Contacts - relatedNames property causes crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-11-23T21:58:36.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sRelease 5.1.2
ComponentsiOS
Labelscontacts, qe-5.1.0
ReporterHarry Bryant
AssigneeChee Kiat Ng
Created2015-11-18T20:11:58.000+0000
Updated2015-11-26T03:49:09.000+0000

Description

Description:

Creating a new contact with Ti.createContact() & including the relatedNames will cause the following error when build to an iOS8 Device / Sim:
[ERROR] :  Script Error {
[ERROR] :      column = 33;
[ERROR] :      line = 155;
[ERROR] :      message = "-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17023e340";
[ERROR] :      sourceURL = "<file:///private/var/mobile/Containers/Bundle/Application/2F169FDD-5809-41DC-82A7-98E5ACB036FC/TIMOB_20010.app/app.js>";
[ERROR] :      stack = "[native code]<nfile:///private/var/mobile/Containers/Bundle/Application/2F169FDD-5809-41DC-82A7-98E5ACB036FC/TIMOB_20010.app/app.js:155:33>";
[ERROR] :  }
The same code will work successfully when build to an iOS9 Device / Sim, and removing the relatedNames property resolves the issue for iOS8.

Steps to reproduce:

1. Create a Classic Project. 2. Include following demo code to app.js:
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});

	Ti.Contacts.requestAuthorization(function(e) {
		if (e.success == true) {
			alert('success');
		}
		else {
			alert('no');
		}
	});

 


var createContact = Ti.UI.createButton({
	title: "Create New Contact",
});



createContact.addEventListener('click',function(e){
	    pong = Ti.Contacts.createPerson({
 		firstName: 'letter',
  		lastName: 'pong',
  		middleName: 'long',
  		nickname: 'fancyPants',
  		prefix: 'Mr',
  		suffix: 'Jr',
  		firstPhonetic: 'a',
  		middlePhonetic: 'b',
  		lastPhonetic: 'c',
  		organization: 'appcelerator',
  		department: 'SDK',
  		jobTitle: 'pingPongChampion',
  		note: 'when i was young, i ping pong to the top',
  		kind: Ti.Contacts.CONTACTS_KIND_PERSON,
  		address:{
    	work:[
	      {
	        CountryCode: 'gb', // determines how the address is displayed
	        Street: '200 Brook Drive\nGreen Park',
	        City: 'Reading',
	        Country: 'England',
	        PostalCode: 'RG2 6UB'
	      },
	      {
	        CountryCode: 'gb', // determines how the address is displayed
	        Street: '1 St Pauls Road\nClerkenwell',
	        City: 'City of London',
	        State: 'London',
	        Country: 'England',
	        PostalCode: 'EC1 1AA'
	      }
	    ],
	    home:[
	      {
	        CountryCode: 'gb', // determines how the address is displayed
	        Street: '2 Boleyn Court',
	        City: 'London',
	        State: 'Greenwich',
	        Country: 'England',
	        PostalCode: 'SE10'
	      }
	    ]
	  },
	  email:{
       home : [
           'myGmail',
          'myHotmail'
       ],
      work : [
          'myWorkemail'
       ]
   	},
   	  relatedNames:{
   	  	father: 'baba',
   	  	mother: 'mama',
   	  	child: 'gaga'
   	  },
	  birthday: '2012-01-01T12:00:00.000+0000',
	  instantMessage:{
	    home:[
	      {
	        service: 'AIM',
	        username: 'leisureAIM'
	      },
	      {
	        service: 'MSN',
	        username: 'no_paul_here@msn.com'
	      }
	    ],
	    work:[
	      {
	        service: 'AIM',
	        username: 'seriousAIM'
	      }
	    ]
	  },
	  organization: 'Appcelerator',
	  phone:{
	    main: ['07900 000001', '07900 000002'],
	    iPhone: ['+44 (0)118 925 6128', '+44 (0)118 000 0000']
	  },
	  alternateBirthday: {
            calendarIdentifier: 'chinese',
            day: 25,
            era: 78,
            isLeapMonth: false,
            month: 11,
            year: 16
        },
        socialProfile:{
	        home:[{
	            service: 'facebook',
	            username: 'jdeep@facebook.com'
	        },
	        {
	            service: 'gamecenter',
	            username: 'jdeep@hotmail.com'
	        }],
	        work:[{
	            service: 'linkedin',
	            username: 'jdeep@linkedin.com'
	        }]
        },
 
	  url:{
	    homepage: ['www.google.com'],
	    work: ['www.appcelerator.com', 'www.example.com']
	  },
	  date:{
	  	anniversary: ['2006-06-25T12:00:00.000+0000','2007-06-25T12:00:00.000+0000'],
	  	other: ['2009-03-25T12:00:00.000+0000']
	  }
	});
  
});


win1.add(createContact);
win1.open();

4. Build to iOS8 device / sim 5. Receive above error. 6. Remove relatedNames property. 7. Build to IOS8 device / sim. 8. Create Contacts works successfully.

Result:

Create Contacts will crash and return aforementioned error on iOS8.

Expected Result:

Create contacts should work successfully on iOS8, or return a warning to exclude the relatedName property when building for iOS8.

Comments

  1. Chee Kiat Ng 2015-11-18

    The sample code is wrong. As according to the docs, relatedNames expect a dictionary of keys with values that are ARRAYs. HOWEVER, this also uncovered that the iOS9 implementation is wrong, fix coming shortly.
  2. Chee Kiat Ng 2015-11-19

    Master PR: https://github.com/appcelerator/titanium_mobile/pull/7467 5_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/7468 (Do not merge until 5.1.0.GA released)

    To test:

    Use the above sample code, but relatedNames should be
       relatedNames:{
          	  	father: ['baba1','baba2'],
          	  	mother: ['mama'],
          	  	child: ['gaga']
          	  }
       
  3. Hans Knöchel 2015-11-23

    Alright. The functionality works now, but only when modifying the provided demo code with the values of the last comment. I cleaned up the test case and provided some more details to check (null check after contact creation, 5.1.0 method for requesting permissions). Updated demo code (as stated in the docs): https://gist.github.com/hansemannn/01f37c1fc6f31e818abd
  4. Harry Bryant 2015-11-23

    Verified as fixed, built the sample code using SDK 5.1.1.v20151123140433 to iOS9 device after modifying the relatedNames to the correct implementation. The contact was created successfully and the relatedNames fields have been saved correctly. Tested with: Devices: iPhones 6S+ (9.1) Simulators: (9.1) & (8.4) Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.1.v20151123140433 Appc Studio: 4.4.0.201511182122 Appc NPM: 4.2.2 Appc CLI: 5.1.0-60 Alloy: 1.7.26 Xcode 7.1(7B91b) Node v0.12.7 *Closing ticket.*
  5. Chee Kiat Ng 2015-11-26

    To Note: This ticket is marked 5.1.2 but PR was merged in 5.1.1GA

JSON Source