Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19896] iOS: Ti.Contacts.getAllPeople() | Custom fields for phone, address and email returns undefined

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-11-11T04:17:57.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sRelease 5.1.0
ComponentsiOS
Labelscontacts, custom, ios, labels, mobile
ReporterMichael Woode
AssigneeChee Kiat Ng
Created2015-11-02T12:56:02.000+0000
Updated2015-11-11T19:54:57.000+0000

Description

When trying to show information about contacts from the iOS Contacts app which have custom field names for phone numbers or emails or address, the Ti.Contacts.Person property 'email', 'phone' or 'adress' is undefined. Which means you can't retrieve any of the emails, phone numbers or addresses (with custom field names) associated with the contact. To replicate, start iOS (version 9.x) simulator. Add a new contact, add one email address with one of the default "labels" provided by iOS, run test code (see below), the email address is listed in the console (as expected), modify the newly added person and add another email address but define a custom label to this entry, run code, the "email" property will be undefined. This can also be reproduced for the "phone" and "address" properties. Tested with Ti SDK 5.0.2.GA
var win = Ti.UI.createWindow({
	backgroundColor: '#fff',
});

var performAddressBookFunction = function() {
	var singleValue = ['firstName', 'lastName', 'fullName'];
	var multiValue = ['email', 'address', 'phone'];
	var people = Ti.Contacts.getAllPeople();
	Ti.API.info('Total contacts: ' + people.length);
	for (var i = 0,
	    ilen = people.length; i < ilen; i ++) {
		Ti.API.info('---------------------');
		var person = people[i];
		for (var j = 0, jlen = singleValue.length; j < jlen; j ++) {
			Ti.API.info(singleValue[j] + ': ' + person[singleValue[j]]);
		}
		for (var j = 0, jlen = multiValue.length; j < jlen; j ++) {
			Ti.API.info(multiValue[j] + ': ' + JSON.stringify(person[multiValue[j]]));
		}
	}

};

var addressBookDisallowed = function() {
	alert('Hey! You disallowed this, why?');
};

var button = Ti.UI.createButton({
	title: 'Output contacts to console',
	height: 50
});
win.add(button);

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

win.open();

Attachments

FileDateSize
max_mustermann.vcf2015-11-11T03:53:44.000+0000252

Comments

  1. Michael Woode 2015-11-09

  2. Hans Knöchel 2015-11-09

    Thank you [~woodoo], we will try to reproduce it asap!
  3. Chee Kiat Ng 2015-11-11

  4. Hans Knöchel 2015-11-11

    CR + FT passed, PR approved!
  5. Michael Woode 2015-11-11

    I can also confirm, its fixed (tested with Ti SDK 5.1.0.v20151110202023 & Ti SDK 5.2.0.v20151111000425)! Thank You all, for the rapid response, this was a key function in our app.
  6. Harry Bryant 2015-11-11

    Verified as fixed, Tested the above sample code with a new contact, both with custom & default field entries. As stated above, fields return as undefined when app is built with 5.0.2.GA SDK and the contact contains custom field entries, works correctly when only default entries are present. using 5.1.0.v20151110202023 the same contact returns both default & custom field entries correctly, for phone, address, and email. Attempted to reproduce the crash with the attached contact, but was unable to do so on the tested devices. Tested on iPhone 6S Plus (9.1) , iPhone 6 Plus (8.3) , iPhone 6S Simulator (9.1) Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.0.v20151110202023 Appc NPM: 4.2.1 Appc CLI: 5.1.0-50 Ti CLI: 5.0.4 Alloy: 1.7.24 Xcode 7.1(7B91b) Node v0.12.7 production Closing ticket.

JSON Source