objective c - How to delete particular user's chat from XMPP server in iOS? -


i new in iphone application development. working on chat app in ios using xmpp , ejabberd. not able delete chat of particular user (not single message).

    -(void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {     [self deletemessagechat:indexpath];     if (editingstyle == uitableviewcelleditingstyledelete)     {         [messages removeobjectatindex:indexpath.row];         [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath]                          withrowanimation:uitableviewrowanimationfade];     } }  -(void)deletemessagechat :(nsindexpath *)indexpath {     self.cls=[self.arrprofile objectatindex:indexpath.row];     nsstring *userjid = [nsstring stringwithformat:@"%@%@",self.cls.userid,xmppserver];     xmppmessagearchivingcoredatastorage *storage = appdelegate.xmppmessagearchivingstorage;     nsmanagedobjectcontext *moc = [storage mainthreadmanagedobjectcontext];     nsentitydescription *entitydescription = [nsentitydescription entityforname:@"xmppmessagearchiving_message_coredataobject"                                                          inmanagedobjectcontext:moc];     nsfetchrequest *request = [[nsfetchrequest alloc]init];     [request setentity:entitydescription];     nsstring *predicatefrmt = @"barejidstr == %@";     nserror *error;     nspredicate *predicate = [nspredicate predicatewithformat:predicatefrmt, userjid];     request.predicate = predicate;     nsarray *messages_new = [moc executefetchrequest:request error:&error];      nsmanagedobject *obj=[messages_new objectatindex:indexpath.row];     [moc deleteobject:obj];      error = nil;     if (![moc save:&error])     {         nslog(@"error deleting movie, %@", [error userinfo]);     } } 

please me solved problem.

i did in code. try edit according arrays.

nsstring *userjid = [nsstring stringwithformat:@"%@%@",cell.frndname.text,domainname];         nsstring *userjid1= [nsstring stringwithformat:@"%@%@",[[nsuserdefaults standarduserdefaults]valueforkey:@"name"],domainname];          nsfetchrequest *messagescored = [[nsfetchrequest alloc] init];         nsmanagedobjectcontext *context=[[self appdelegate].xmppmessagearchivingcoredatastorage mainthreadmanagedobjectcontext];         nsentitydescription *messageentity = [nsentitydescription entityforname:@"xmppmessagearchiving_contact_coredataobject" inmanagedobjectcontext:context];           [messagescored setentity:messageentity];         [messagescored setincludespropertyvalues:no]; //only fetch managedobjectid         nsstring *predicatefrmt = @"barejidstr == %@";         nsstring *predicatefrmt1 = @"streambarejidstr == %@";         nspredicate *predicatename = [nspredicate predicatewithformat:predicatefrmt,userjid];         nspredicate *predicatessid = [nspredicate predicatewithformat:predicatefrmt1,userjid1];          nsarray *subpredicates = [nsarray arraywithobjects:predicatename, predicatessid, nil];          nspredicate *orpredicate = [nscompoundpredicate andpredicatewithsubpredicates:subpredicates];          messagescored.predicate = orpredicate;         nserror * error = nil;         nsarray * messages = [context executefetchrequest:messagescored error:&error];         //error handling goes here          [tableview reloaddata];         (nsmanagedobject * message in messages)         {             [context deleteobject:message];             [tableview reloaddata];         }         nsentitydescription *messageentity1 = [nsentitydescription entityforname:@"xmppmessagearchiving_message_coredataobject" inmanagedobjectcontext:context];         [messagescored setentity:messageentity1];         [messagescored setincludespropertyvalues:no]; //only fetch managedobjectid          messagescored.predicate = orpredicate;         nsarray * messages1 = [context executefetchrequest:messagescored error:&error];         //error handling goes here         [tableview reloaddata];         (nsmanagedobject * message in messages1)         {             [context deleteobject:message];             [tableview reloaddata];         }          nserror *saveerror = nil;         [context save:&saveerror]; 

i added code in commiteditingstyle delegate method. here pass friend name in userjid , logged in user name in userjid1.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -