开发者

how to send message to particular email id using Xmpp in iphone

i am trying application using Xmpp.i created a login page(emailid,password,hostname(talk.google.com)) .this is the first page what i created.After pressing the login button(if successful we will enter into next view) and then we will get another view in that it consists of two text views one for emailid(for whom we r going to send the message)and another for message(to send message)and by clicking send button i have to send message..the main problem for me is successfully i am get logged but after the i cant send message to that mail id..can any one help me in doing this task and the code is belo

thank you girish

-(IBAction)SendButtonPressed:(id)sender
{
    NSLog(@"send button clicked");
    [self.msgTextView resignFirstResponder];
    //NSString *user;
    //user=emialTextField.text;
 开发者_JAVA技巧   //[self.emialTextField resignFirstResponder];


    //XMPPUserCoreDataStorage *user = [(XMPPUserCoreDataStorage *) emialTextField.text];

    XMPPJID *jid=[XMPPJID jidWithString:emialTextField.text];
    [[self xmppStream] setMyJID:jid];


    XMPPApplicationAppDelegate *appDelegate=(XMPPApplicationAppDelegate *)[[UIApplication sharedApplication] delegate];
    xmppStream=[appDelegate xmppStream];
    //self.user.displayName;

    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    [body setStringValue:self.msgTextView.text];

    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];

    //[message addAttributeWithName:@"to" stringValue:[user jid]];
    [message addAttributeWithName:@"to" stringValue:self.emialTextField.text];

    [message addChild:body];

    [xmppStream sendElement:message];
}


Here,

use this code to send the messages to any JID on your domain.

- (void)sendMessage:(NSString *)userId
{

NSString *messageStr = @"Hello...";

if([messageStr length] > 0)
{
    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    [body setStringValue:messageStr];

    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:userId];
    [message addChild:body];

    [[self xmppStream] sendElement:message];



}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜