iOS XMPP received message in coversation screen
-
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
-
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
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.
-
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.
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 .
-
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
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 aUIAlertView
then maybe you shouldn't use that?