Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Objective-C and Swift
  4. iOS XMPP received message in coversation screen

iOS XMPP received message in coversation screen

Scheduled Pinned Locked Moved Objective-C and Swift
ioshelpworkspace
4 Posts 3 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 11766967
    wrote on last edited by
    #1

    I am working on XMPP based project. i am able to send message and it displays in conversation screen but when i receive message it only show in alertview not able to see in conversation screen. help me please.

     - (void)viewDidLoad {
    \[super viewDidLoad\];
    // Do any additional setup after loading the view.
    
    \[\[NSNotificationCenter defaultCenter\] addObserver:self selector:@selector(messageReceived:) name:MessageRecivedNotif object:nil\];
    
    appdelegate=(AppDelegate\*)\[\[UIApplication sharedApplication\] delegate\];
    \[self getAllMessagesArrayWithOppositeUser:\_jid\];
    
    \[\[NSNotificationCenter defaultCenter\] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification
                                               object:nil\];
    
    
    }
    
    #pragma mark table delegate and datasource methods
     - (NSInteger)tableView:(UITableView \*)tableView numberOfRowsInSection:(NSInteger)section
    {
    return data.count;
    }
    - (UITableViewCell \*)tableView:(UITableView \*)tableView cellForRowAtIndexPath:(NSIndexPath \*)indexPath
    {
    UITableViewCell \*cell = \[tblobj dequeueReusableCellWithIdentifier:@"cell"\];
    UILabel \*lbl;
    if (cell==nil)
    {
        cell = \[\[UITableViewCell alloc\]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"\];
        
        if (chatLblRight == 1)
        {
            lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
            \[lbl setTextColor:\[UIColor redColor\]\];
            \[cell.contentView   addSubview:lbl\];
        }
        
        
     }
     if (chatLblRight == 1)
     {
        lbl.text = \[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
        chatLblRight = 0;
        lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
        \[lbl setTextColor:\[UIColor redColor\]\];
        \[cell.contentView   addSubview:lbl\];
    
        return cell;
      }
      else
      {
        cell.textLabel.text=\[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
        return cell;
      }
    }
    -(void)messageReceived:(NSNotification\*)notif
    {
    XMPPMessage \*message=(XMPPMessage\*)notif.object;
    NSString \*body = \[\[message elementForName:@"body"\] stringValue\];
    NSMutableDictionary \*dic\_recive = \[\[NSMutableDictionary alloc\]init\];
    \[dic\_recive setObject:body forKey:@"text"\];
    \[data
    
    L D 2 Replies Last reply
    0
    • M Member 11766967

      I am working on XMPP based project. i am able to send message and it displays in conversation screen but when i receive message it only show in alertview not able to see in conversation screen. help me please.

       - (void)viewDidLoad {
      \[super viewDidLoad\];
      // Do any additional setup after loading the view.
      
      \[\[NSNotificationCenter defaultCenter\] addObserver:self selector:@selector(messageReceived:) name:MessageRecivedNotif object:nil\];
      
      appdelegate=(AppDelegate\*)\[\[UIApplication sharedApplication\] delegate\];
      \[self getAllMessagesArrayWithOppositeUser:\_jid\];
      
      \[\[NSNotificationCenter defaultCenter\] addObserver:self
                                               selector:@selector(keyboardWasShown:)
                                                   name:UIKeyboardDidShowNotification
                                                 object:nil\];
      
      
      }
      
      #pragma mark table delegate and datasource methods
       - (NSInteger)tableView:(UITableView \*)tableView numberOfRowsInSection:(NSInteger)section
      {
      return data.count;
      }
      - (UITableViewCell \*)tableView:(UITableView \*)tableView cellForRowAtIndexPath:(NSIndexPath \*)indexPath
      {
      UITableViewCell \*cell = \[tblobj dequeueReusableCellWithIdentifier:@"cell"\];
      UILabel \*lbl;
      if (cell==nil)
      {
          cell = \[\[UITableViewCell alloc\]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"\];
          
          if (chatLblRight == 1)
          {
              lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
              \[lbl setTextColor:\[UIColor redColor\]\];
              \[cell.contentView   addSubview:lbl\];
          }
          
          
       }
       if (chatLblRight == 1)
       {
          lbl.text = \[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
          chatLblRight = 0;
          lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
          \[lbl setTextColor:\[UIColor redColor\]\];
          \[cell.contentView   addSubview:lbl\];
      
          return cell;
        }
        else
        {
          cell.textLabel.text=\[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
          return cell;
        }
      }
      -(void)messageReceived:(NSNotification\*)notif
      {
      XMPPMessage \*message=(XMPPMessage\*)notif.object;
      NSString \*body = \[\[message elementForName:@"body"\] stringValue\];
      NSMutableDictionary \*dic\_recive = \[\[NSMutableDictionary alloc\]init\];
      \[dic\_recive setObject:body forKey:@"text"\];
      \[data
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Member 11766967 wrote:

      Where is my mistake ?

      Could be anywhere. You need to do some debugging for yourself and identify where things are going wrong. Then edit your question and add the detail to explain exactly what is or is not happening that should be. Also please put <pre></pre> tags around your code so people can read it clearly.

      M 1 Reply Last reply
      0
      • L Lost User

        Member 11766967 wrote:

        Where is my mistake ?

        Could be anywhere. You need to do some debugging for yourself and identify where things are going wrong. Then edit your question and add the detail to explain exactly what is or is not happening that should be. Also please put <pre></pre> tags around your code so people can read it clearly.

        M Offline
        M Offline
        Member 11766967
        wrote on last edited by
        #3

        thanks for your replay. i am new in ios. can you please tell me how i check for received message? i have removed alertview from my didreceivemessage method and then i am not able to received message. i have updated my code of appdelegate.m file and method didreceivemessage. kindly replay. thanks .

        1 Reply Last reply
        0
        • M Member 11766967

          I am working on XMPP based project. i am able to send message and it displays in conversation screen but when i receive message it only show in alertview not able to see in conversation screen. help me please.

           - (void)viewDidLoad {
          \[super viewDidLoad\];
          // Do any additional setup after loading the view.
          
          \[\[NSNotificationCenter defaultCenter\] addObserver:self selector:@selector(messageReceived:) name:MessageRecivedNotif object:nil\];
          
          appdelegate=(AppDelegate\*)\[\[UIApplication sharedApplication\] delegate\];
          \[self getAllMessagesArrayWithOppositeUser:\_jid\];
          
          \[\[NSNotificationCenter defaultCenter\] addObserver:self
                                                   selector:@selector(keyboardWasShown:)
                                                       name:UIKeyboardDidShowNotification
                                                     object:nil\];
          
          
          }
          
          #pragma mark table delegate and datasource methods
           - (NSInteger)tableView:(UITableView \*)tableView numberOfRowsInSection:(NSInteger)section
          {
          return data.count;
          }
          - (UITableViewCell \*)tableView:(UITableView \*)tableView cellForRowAtIndexPath:(NSIndexPath \*)indexPath
          {
          UITableViewCell \*cell = \[tblobj dequeueReusableCellWithIdentifier:@"cell"\];
          UILabel \*lbl;
          if (cell==nil)
          {
              cell = \[\[UITableViewCell alloc\]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"\];
              
              if (chatLblRight == 1)
              {
                  lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
                  \[lbl setTextColor:\[UIColor redColor\]\];
                  \[cell.contentView   addSubview:lbl\];
              }
              
              
           }
           if (chatLblRight == 1)
           {
              lbl.text = \[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
              chatLblRight = 0;
              lbl = \[\[UILabel alloc\]initWithFrame:CGRectMake(200, 10, 150, 44)\];
              \[lbl setTextColor:\[UIColor redColor\]\];
              \[cell.contentView   addSubview:lbl\];
          
              return cell;
            }
            else
            {
              cell.textLabel.text=\[\[data objectAtIndex:indexPath.row\]valueForKey:@"text"\];
              return cell;
            }
          }
          -(void)messageReceived:(NSNotification\*)notif
          {
          XMPPMessage \*message=(XMPPMessage\*)notif.object;
          NSString \*body = \[\[message elementForName:@"body"\] stringValue\];
          NSMutableDictionary \*dic\_recive = \[\[NSMutableDictionary alloc\]init\];
          \[dic\_recive setObject:body forKey:@"text"\];
          \[data
          
          D Offline
          D Offline
          Dennis E White
          wrote on last edited by
          #4

          Member 11766967 wrote:

          when i receive message it only show in alertview not able to see in conversation screen. help me please.

          maybe I am missing something here?? In your didReceiveMessage method you are displaying an alertView when the app is active. otherwise you are displaying it as a notification. I guess if you don't want to see it in a UIAlertView then maybe you shouldn't use that?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups