Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-12133

iOS: Titanium.Contacts.getAllPeople() is cached

    Details

      Description

      Actual result
      If a contact record is updated in the global Address Book while the app is running in the background, Titanium.Contacts.getAllPeople() is not updated.

      Expected result
      What I suggest is to add a new method called reloadContacts() which will update the cache.

      Test case

      var tabGroup = Titanium.UI.createTabGroup();
       
      var win = Titanium.UI.createWindow({
      	backgroundColor : "#fff",
      	tabBarHidden : true
      });
       
      var tab1 = Titanium.UI.createTab({
      	title : 'Tab 1',
      	window : win
      });
       
      var android = (Ti.Platform.osname === 'android');
       
      var activityIndicator;
      if (android) {
      	activityIndicator = Ti.UI.createActivityIndicator({
      		message : 'Loading all contacts, please wait...'
      	});
      	activityIndicator.show();
      }
       
      var makeTable = function() {
      	Ti.API.info("Making table...");
      	var people = Titanium.Contacts.getAllPeople();
      	var rows = [];
      	for (var i = 0; i < people.length; i++) {
      		Ti.API.info("People object is: " + people[i]);
      		var title = people[i].fullName;
      		if (!title || title.length === 0) {
      			title = "(no name)";
      		}
      		rows[i] = Ti.UI.createTableViewRow({
      			title : title,
      			person : people[i],
      			hasChild : true
      		});
      		rows[i].addEventListener('click', function(e) {
      			var display = Ti.UI.createWindow({
      				backgroundColor : 'white',
      				title : e.row.person.fullName
      			});
      			var top = 0;
      			var showedSomething = false;
      			for (var label in e.row.person.address) {
      				top += 20;
      				var addrs = e.row.person.address[label];
      				for (var i = 0; i < addrs.length; i++) {
      					var info = Ti.UI.createLabel({
      						text : '(' + label + ') ' + addrs[i].Street,
      						top : top,
      						left : 20,
      						height : 'auto',
      						width : 'auto'
      					});
      					display.add(info);
      					showedSomething = true;
      				}
      			}
      			if (!showedSomething) {
      				display.add(Ti.UI.createLabel({
      					text : 'No addresses to show'
      				}));
      			}
      			tab1.open(display, {
      				animated : true
      			});
      		});
      	}
      	return rows;
      };
       
      var tableview = Ti.UI.createTableView({
      	data : makeTable()
      });
       
      win.add(tableview);
       
      if (android && activityIndicator) {
      	activityIndicator.hide();
      }
       
      Ti.App.addEventListener("resumed", function(e) {
      	Ti.API.info("Resumed");
      	
      	// Reload data
      	tableview.setData([]);
          tableview.setData(makeTable());
      });
       
      tabGroup.addTab(tab1);
      tabGroup.open();

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vduggal Vishal Duggal (Inactive)
                Reporter:
                dsefton Daniel Sefton
                Reviewer:
                Sabil Rahim
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-15223
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration