Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13496] iOS: Titanium.Contacts.removeGroup fails

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-06-04T20:36:22.000+0000
Affected Version/sRelease 3.0.2, Release 3.1.0
Fix Version/s2013 Sprint 12 API, 2013 Sprint 12, Release 3.2.0
ComponentsiOS
Labelsmodule_media, qe-testadded
ReporterMark Burggraf
AssigneeIngo Muschenetz
Created2013-01-23T16:19:02.000+0000
Updated2013-10-15T10:04:48.000+0000

Description

The following code fails: Titanium.Contacts.removeGroup(groupObj); Titanium.Contacts.save(); The error given is:
[ERROR] :  Invalid type passed to function. expected: TiContactsPerson, was: TiContactsGroup  in -[ContactsModule removePerson:] (ContactsModule.m:431)
Looking at ContactsModule.m it appears there may be a bug in removeGroup -- it seems to be using code from removePerson. See below:
-(void)removeGroup:(id)arg
{
	ENSURE_SINGLE_ARG(arg,TiContactsGroup)
	ENSURE_UI_THREAD(removePerson,arg)

	[self removeRecord:[arg record]];
}

Comments

  1. Pedro Enrique 2013-04-03

    Please provide a runnable sample app.js
  2. Mark Burggraf 2013-04-03

       var win = Titanium.UI.createWindow({  
           backgroundColor:"#fff",
           layout:"vertical"
       });
       
       function createGroup()
       {
       	var newGroup = Titanium.Contacts.createGroup();
       	newGroup.name = "Test Group 1";
       	Titanium.Contacts.save();	
       }
       function removeGroup()
       {
       	var 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")
       		{
       			Titanium.Contacts.removeGroup(allGroups[i]);
       		}
       	}
       	Titanium.Contacts.save();
       }
       
       var createButton = Ti.UI.createButton({title:"Create Group: Test Group 1",top:20});
       var removeButton = Ti.UI.createButton({title:"Remove Group: Test Group 1",top:20});
       createButton.addEventListener("click",createGroup);
       removeButton.addEventListener("click",removeGroup);
       
       win.add(createButton);
       win.add(removeButton);
       
       win.open();
       
  3. Mark Burggraf 2013-04-03

    Running the app.js above gives the error: [ERROR] :  Invalid type passed to function. expected: TiContactsPerson, was: TiContactsGroup in -[ContactsModule removePerson:] (ContactsModule.m:431) This error is not trappable via a try/catch block, though, since it's thrown at the lower (module) level.
  4. Daniel Sefton 2013-04-08

    Confirmed with 3.0.2 GA, but the issue is fixed in 3.1.0.v20130403114957.
  5. Mark Burggraf 2013-04-09

    As of 3.1.0.v20130405170202, this is still not working for us.
  6. Mark Burggraf 2013-04-09

    Here is updated test code that shows it is not fixed:
       var win = Titanium.UI.createWindow({  
           backgroundColor:"#fff",
           layout:"vertical"
       });
       
       function createGroup()
       {
       	var newGroup = Titanium.Contacts.createGroup();
       	newGroup.name = "Test Group 2";
       	Titanium.Contacts.save();	
       	Ti.API.info("********************");
       	Ti.API.info("Listing groups:");
       	Ti.API.info("********************");
       	allGroups = Titanium.Contacts.getAllGroups();
       	for (var i=0; i < allGroups.length; i++)
       	{
       		Ti.API.info("found group name: " + allGroups[i].name);
       	}	
       	Ti.API.info("********************");
       	Ti.API.info("done");
       	Ti.API.info("********************");	
       }
       function removeGroup()
       {
       	var 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 2")
       		{
       			Ti.API.info("deleting group: Test Group 2");
       			Titanium.Contacts.removeGroup(allGroups[i]);
       			Titanium.Contacts.save();
       		}
       	}	
       	Ti.API.info("********************");
       	Ti.API.info("Listing groups again");
       	Ti.API.info("********************");
       	allGroups = Titanium.Contacts.getAllGroups();
       	for (var i=0; i < allGroups.length; i++)
       	{
       		Ti.API.info("found group name: " + allGroups[i].name);
       	}	
       	Ti.API.info("********************");
       	Ti.API.info("done");
       	Ti.API.info("********************");
       	
       }
       
       var createButton = Ti.UI.createButton({title:"Create Group: Test Group 2",top:20});
       var removeButton = Ti.UI.createButton({title:"Remove Group: Test Group 2",top:20});
       createButton.addEventListener("click",createGroup);
       removeButton.addEventListener("click",removeGroup);
       
       win.add(createButton);
       win.add(removeButton);
       
       win.open();
       
       
  7. Mark Burggraf 2013-04-09

    Note that, beginning in SDK 3.1, the original error message reported no longer appears. No error is given -- the method simply does not delete the group as it's supposed to.
  8. Daniel Sefton 2013-04-09

    Ok, confirmed. Our engineering team will review. Thanks.
  9. Sabil Rahim 2013-06-04

    Fixed in master (3.2.0) by PR https://github.com/appcelerator/titanium_mobile/pull/3884
  10. Paras Mishra 2013-10-15

    Group is getting removed on the invocation of Titanium.Contacts.removeGroup Verified fix on: Device : iPhone 5 , iOS version : 7.0 Device : iPod Touch , iOS version : 6.1.3 SDK: 3.2.0.v20131014204636 CLI version : 3.2.0 OS : MAC OSX 10.8.4 Alloy : 1.2.2 Appcelerator Studio, build: 3.2.0.201310112258 XCode : 5

JSON Source