Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20193] iOS: Ti.Contacts Cannot create a new entry with unsaved changes

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-06-09T21:54:13.000+0000
Affected Version/sRelease 5.1.2, Release 5.1.1
Fix Version/sRelease 5.4.0
ComponentsiOS
LabelsiOS, qe-5.1.2, qe-5.4.0
ReporterHarry Bryant
AssigneeAngel Petkov
Created2016-01-04T23:51:29.000+0000
Updated2016-06-09T21:54:41.000+0000

Description

Comments

  1. Srikanth Sombhatla 2016-01-06

    PR https://github.com/appcelerator/titanium_mobile/pull/7613 Also I see an issue with the test case - Ti.Contacts.save() should be called after Ti.Contacts.removeGroup() to commit the changes, not at the end of the loop. Use the following app.js for verifying the PR.
       var win = Ti.UI.createWindow({
         backgroundColor: "White"
       });
        
       var newGroup = null;
       var allGroups = null;
       var failCase = null;
        
       function testCase(){
         if(failCase != null) {
         return false;
         } else{
           return true;
         }
       }
        
       var createPerson = Ti.UI.createButton({
         title: 'Create Person 1',
         top: '35%'
       });
        
       createPerson.addEventListener('click', function(){
         var newPerson = Ti.Contacts.createPerson({
           firstName: 'Testing',
           lastName: '123'
           
         });
         
         Ti.Contacts.save();
       });
        
       var createGroup = Ti.UI.createButton({
         title: 'Create Test Group 1',
         top: '20%',
       });
        
       var removeGroup = Ti.UI.createButton({
         title: 'Remove Test Group 1',
         bottom: '20%'
       });
        
       var findGroup = Ti.UI.createButton({
         title: 'Find Test Group 1',
         top: '50%'
       });
        
       createGroup.addEventListener('click', function(){
         newGroup = Ti.Contacts.createGroup();
         newGroup.name = "Test Group 1";
         Ti.API.info("Test Group 1 Created!");
         Ti.Contacts.save();
       });
        
       removeGroup.addEventListener('click', function(){
          allGroups = Titanium.Contacts.getAllGroups();
          
               for (var i = 0; i < allGroups.length; i++) {
                   Ti.API.info("found group name: " + allGroups[i].name);
                   if (allGroups[i].name == "Test Group 1") {
                       Ti.Contacts.removeGroup(allGroups[i]);
                       Ti.Contacts.save();         
                       Ti.API.info(allGroups[i].name + " Successfully Removed!");
                       failCase = null;
                   } else {
                     Ti.API.info("Failed to remove group: " + allGroups[i].name);
                     failCase = "Not Found";
                   }
               }
              
       });
        
       findGroup.addEventListener('click', function(){
         allGroups = Titanium.Contacts.getAllGroups();
         Ti.Contacts.save();
               for (var i = 0; i < allGroups.length; i++) {
                   Ti.API.info("found group name: " + allGroups[i].name);
                   
                   if (allGroups[i].name == "Test Group 1") {
                       Ti.API.info('Test Group 1 Found!');
                       failCase = null;
                       
                   } else if(allGroups[i].name != "Test Group 1" || allGroups[i].name == null) {
                     Ti.API.info('Test Group 1 Not Found');
                     failCase = "Not Found";
                   }
               }
       });
        
       win.add(createPerson);
       win.add(createGroup);
       win.add(removeGroup);
       win.add(findGroup);
       win.open();
       
       
  2. Angel Petkov 2016-01-06

    FT AND CR approved merging. Thanks Skrilkanth. However for calling the Ti.Contacts.Save() doesn't work for a single person.If that is indeed a bug, we should create a separate ticket for that.
  3. Wilson Luu 2016-01-11

    [~ssombhatla], Can you add the fix version for this ticket?
  4. Srikanth Sombhatla 2016-01-14

    [~apetkov] Sorry I did not quite understand - Ti.Contacts.Save() doesn't work for a single person. Can you please elaborate or best if you think it is an issue please do create a ticket. Thanks.
  5. Angel Petkov 2016-01-14

    [~sriks] When calling the save function for a single contact as appose to a group. It doesn't seem to work, however I'm not too familiar with the contact module. So I'm not sure if the save method is indeed meant for a single contact or for groups only.
  6. Harry Bryant 2016-06-09

    Verified as fixed, I am able to create and remove groups after making changes. Tested On: iPhone 6S (9.3.2) Device Mac OSX El Capitan 10.11.5 Ti SDK: 5.4.0.v20160608165242 Appc Studio: 4.6.0.201605180604 Appc NPM: 4.2.7.-2 App CLI: 5.4.0-11 Xcode 7.3 Node v4.2.6 *Closing ticket.*

JSON Source