Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19508] iOS9: Properties of person is unavailable (module Ti.Contacts)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-09-14T13:45:49.000+0000
Affected Version/sRelease 5.0.0
Fix Version/sRelease 5.0.0
ComponentsiOS
LabelsTi.Contacts, qe-automation, regression
ReporterTHOMAS LEMAITRE
AssigneeChee Kiat Ng
Created2015-09-11T14:19:10.000+0000
Updated2015-10-01T18:19:47.000+0000

Description

I tested my app and i appears that the module Ti.Contacts is broken. In fact, you can only get the properties "identifier" of a person. Other properties is unavailable and causing crash of the app.
var people = Ti.Contacts.getAllPeople(),
person = null;

for (var i=0, ilen=people.length; i<ilen; i++){
var person = people[i];
Ti.API.log('identifier ' + person.getIdentifier()); //works
Ti.API.log('firstName ' + person.getFirstName()); // didn't works
Ti.API.log('middleName ' + person.getMiddleName()); // didn't works
Ti.API.log('lastName ' + person.getLastName()); // didn't works
//... etc for all other properties of Person except "identifier"
}

Comments

  1. Chee Kiat Ng 2015-09-14

    Master PR:https://github.com/appcelerator/titanium_mobile/pull/7177 backport 5_0_X: https://github.com/appcelerator/titanium_mobile/pull/7178
  2. Chee Kiat Ng 2015-09-14

    PRs approved and merged.
  3. Satyam Sekhri 2015-09-14

    The fix works when we build using iOS SDK 9.0. However, if the app is build using iOS SDK 8.4, then the getAllPeople returns zero contacts even though there are contacts. Hence, it would not output any details in the sample code. Mac OS 10.10.5 Titanium CLI: 5.0.1 SDK: 5.0.0.v20150914021515 Xcode: 7 GM seed
  4. Chee Kiat Ng 2015-09-14

    The reason why it's not working for iOS 8.4 is because the older version of contacts require the developer to explicitly request for permission to access the addressbook. Please use this sample code instead:
       var performAddressBookFunction = function(){
       	var people = Ti.Contacts.getAllPeople(),
       	person = null;
       	 
       	for (var i=0, ilen=people.length; i<ilen; i++){
       	var person = people[i];
       	Ti.API.log('identifier ' + person.getIdentifier()); //works
       	Ti.API.log('firstName ' + person.getFirstName()); // didn't works
       	Ti.API.log('middleName ' + person.getMiddleName()); // didn't works
       	Ti.API.log('lastName ' + person.getLastName()); // didn't works
       	//... etc for all other properties of Person except "identifier"
       	}
       };
       var addressBookDisallowed = function(){
       	Ti.API.log('address book not allowed');
       };
       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();
       }
       
    *Note:* getId() is for iOS8, and is replaced with getIdentifier() for iOS9. So expect to see identifier = undefined when run in iOS8.
  5. Ingo Muschenetz 2015-09-14

    [~bhatfield] looks like an issue for Release Notes.
  6. Satyam Sekhri 2015-09-15

    Contact properties shown. Also checked when build with iOS 8.4 and using code for Kiat that explicitly asks for Contacts permission. Verified on: Mac OS 10.10.5 Appc CLI NPM: 4.2.0-8 Appc CLI Core: 5.0.0-51 Titanium CLI: 5.0.3 Appc Studio: 4.3.0.201509140942 SDK: 5.0.0.v20150914163105 Xcode: 7 GM seed
  7. Benjamin Hatfield 2015-09-17

    [~cng] In your note, shouldn't it be *recordId* for iOS 8? *id* is marked as an Android-only property for Ti.Contacts.Person. http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Contacts.Person-property-recordId http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Contacts.Person-property-id
  8. Chee Kiat Ng 2015-09-18

    my bad. i meant *recordId* for iOS 8.

JSON Source