[TIMOB-4908] getPersonByID crashes if ID does not exist
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-09-08T14:51:22.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | Sprint 2011-36 |
Components | iOS |
Labels | n/a |
Reporter | Alan Leard |
Assignee | Sabil Rahim |
Created | 2011-08-05T13:31:17.000+0000 |
Updated | 2017-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();
PULL PENDING #405 https://github.com/appcelerator/titanium_mobile/pull/405
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); }
getpersonByID returns a NUll if it doesn't exist. and trying to access a null variable fullname would raise an exception in javascript itself.
the correct usage for these methods can be found in KitchenSink.
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
Closing ticket as invalid with reference to the above comments.