2

I am working on chatting app in iOS using xmpp and ejabberd . I am not able to remove single message.

Is this correct method - (void)removeResources:(NSSet *)value to remove chat? And what parameter I need to remove chat?

Or do I need to remove entry from core data? On Quick Blox I found this method:

NSSet *mesagesIDs = [NSSet setWithObjects:@"54fdbb69535c12c2e407c672", @"54fdbb69535c12c2e407c673", nil];      

[QBRequest deleteMessagesWithIDs:mesagesIDs

How to use this in my project without quickblox?

halfer
  • 19,824
  • 17
  • 99
  • 186
Krutarth Patel
  • 3,407
  • 6
  • 27
  • 54

1 Answers1

1

If you have XMPPMessageArchiving_Message_CoreDataObject. i think this object is used to display data in UITableView so you can direct removed that object from core data using below code. Here i am showing to delete loop of messages.

NSManagedObjectContext *moc = [self managedObjectContext];
for (XMPPMessageArchiving_Message_CoreDataObject *message in messages)
    {
        [moc deleteObject:message];

}

Hope this help you.

Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43
  • actually there is not such fuctionality integrated in XMPP chat sample . you need to do your self. – Jatin Patel - JP May 29 '15 at 06:49
  • But you can take reference, how to achieved that using code that is available in `XMPPMessageArchivingCoreDataStorage.m -- > - (void)didCreateManagedObjectContext` .. this method just show that how to delete composing message . so you can take reference of this/ – Jatin Patel - JP May 29 '15 at 06:51
  • i think that this may be solution.thanks where should i call this method? – Krutarth Patel May 29 '15 at 08:35
  • implement on place where you want to delete the message and have object of XMPPMessageArchiving_Message_CoreDataObject. – Jatin Patel - JP May 29 '15 at 08:56
  • i add this code in - (void)tableView:(UITableView *)tableView commitEditingStyle method,i need to delete message by swipe. i add {for (XMPPMessageArchiving_Message_CoreDataObject *message in messages) { [moc deleteObject:message]; if (moc == nil) { } else { }} . but moc is getting nil – Krutarth Patel May 29 '15 at 09:06
  • actually you need somehow get the reference of moc. like NSManagedObjectContext *moc = [self managedObjectContext]; – Jatin Patel - JP May 29 '15 at 09:10
  • Finally i do this code .correct me { NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:messages]; NSManagedObjectContext *moc = [self managedObjectContext]; NSError *error; NSArray *objects = [moc executeFetchRequest:request error:&error]; for (XMPPMessageArchiving_Message_CoreDataObject *message in messages) { [moc deleteObject:message]; if (moc == nil) { } else { } } – Krutarth Patel May 29 '15 at 09:13
  • just delete single message instead of for loop. for (XMPPMessageArchiving_Message_CoreDataObject *message in messages) – Jatin Patel - JP May 29 '15 at 09:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79105/discussion-between-sri-krutarth-and-none). – Krutarth Patel May 29 '15 at 09:29
  • @SriKrutarth, thanks for your appreciation, it keep us motivating. :) – Jatin Patel - JP Jun 01 '15 at 06:59
  • Sir i want to reload the TableView. i try alot but not effective. This is the 'IMMainMessageC' Class in Which 'initWithStyle' this is the Function that work for reloading when new message. i dont know how to Reload the TableView in XMPP when any Message Delete from Tableview.Thanks for advance. – Sawan Cool Jun 12 '15 at 07:56
  • @SawanCool, i assume that you have messages in `NSMutableArray`. so once you perform delete operation to delete data from core data. you also need to delete that object from NSMutableArray as well. and perform deleted row reloading of tableview using following code. [self.tableView beginUpdates]; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourDeletedCell, nil] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView endUpdates]; – Jatin Patel - JP Jun 12 '15 at 08:36