Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1008] Ti.Contacts Reload Event Listener Not Working Properly

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionInvalid
Resolution Date2015-09-30T00:42:15.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterTim Christensen
AssigneeShak Hossain
Created2015-03-24T16:52:51.000+0000
Updated2016-03-08T07:37:20.000+0000

Description

The application I have developed requires a customized contacts list built by calling: Ti.Contacts.getAllPeople(); Because some users have duplicate contacts, multiple linked contacts I de-duplicate the list and store a copy of the contacts with the app. This makes getting the contacts list much faster. However, I need to listen for changes to the contacts and fire off an update to the cached list - most typical is someone adding a contact on-the-fly when using the app. I have implemented the following in app.js: Ti.Contacts.addEventListener('reload', function(e) { ... }); It works just fine until the app is 'swipe quit'. In other words if: -- Launch app, go to contacts, change contact, go back to app, event is fired just fine At any point in time, quitting the app seems to consume the event listener and it will never work again until the app is deleted and reinstalled -- regardless of whether the event listener is added.

Comments

  1. Shuo Liang 2015-03-25

    Hi, Please provide a simple test case to reproduce your problem. That will be helpful to address the problem you have. Here is the guide about [how to create a test case](http://docs.appcelerator.com/titanium/3.0/#!/guide/How_to_Submit_a_Bug_Report-section-29004732_HowtoSubmitaBugReport-CreatingaTestCase) Regards, Shuo
  2. Tim Christensen 2015-03-26

    I figured out what the issue is, not sure if it is a bug or a feature -- the event only fires AFTER Ti.Contacts.getAllPeople() is called. To test: 1. Launch this 2. Go to contacts and change one and save 3. Resume app (function() { var reloadCounter = 0; function reloadContacts() { reloadCounter++; Ti.API.info('Reload Contacts ' + reloadCounter); } function addReloadListener() { Ti.API.info('Adding Reload Listener'); Ti.Contacts.addEventListener('reload', reloadContacts); // This has to be called before the listener will work // Either before or after it is added //Ti.Contacts.getAllPeople(); } if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED) { addReloadListener(); } else if(Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN) { Ti.Contacts.requestAuthorization(function(e) { if(e.success) { addReloadListener(); } }); } })();

JSON Source