Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4908] getPersonByID crashes if ID does not exist

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2011-09-08T14:51:22.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sSprint 2011-36
ComponentsiOS
Labelsn/a
ReporterAlan Leard
AssigneeSabil Rahim
Created2011-08-05T13:31:17.000+0000
Updated2017-03-24T18:22:17.000+0000

Description

If you try to reference Ti.Contacts.getPersonByID(); with an ID that is invalid, it crashes the application. Using an if statement or a try/catch still crashes. See example below:

var win = Titanium.UI.createWindow();

/*Use to find a valid ID
Ti.Contacts.showContacts({
    animated: true,
    selectedPerson: function(e) {
        alert(e.person.recordId);
    }
});
*/

p = Ti.Contacts.getPersonByID(3);
alert(p.fullName);

win.open();

Comments

  1. Sabil Rahim 2011-08-22

    PULL PENDING #405 https://github.com/appcelerator/titanium_mobile/pull/405
  2. Moshe Marciano 2011-09-05

    This fix is fine, but is incomplete. the file ContactPerson.m has a record method of it's own that does not rely on the one fixed in ContactModule.m, therefor, the crash still occurs if you try to use the fullName method on an contactPerson that doesn't exist this is an excerpt: if (record == NULL) { if (recordId != kABRecordInvalidID) { record = ABAddressBookGetPersonWithRecordID([module addressBook], recordId); }
  3. Sabil Rahim 2011-09-08

    getpersonByID returns a NUll if it doesn't exist. and trying to access a null variable fullname would raise an exception in javascript itself.
  4. Sabil Rahim 2011-09-08

    the correct usage for these methods can be found in KitchenSink.
  5. Pedro Enrique 2011-09-15

    Example of this working correctly can be found in this file from the KS: https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/contacts_searchById.js
  6. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source