[AC-1008] Ti.Contacts Reload Event Listener Not Working Properly
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Invalid |
Resolution Date | 2015-09-30T00:42:15.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Tim Christensen |
Assignee | Shak Hossain |
Created | 2015-03-24T16:52:51.000+0000 |
Updated | 2016-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.
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
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(); } }); } })();