如何在iPhone应用程序中实现谷歌聊天 [英] how to implement google chat in iphone app

查看:159
本文介绍了如何在iPhone应用程序中实现谷歌聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了很多但是找不到可以帮助我开始实施谷歌聊天的实际示例源代码,xmpp框架提供的示例代码也没有清楚地说明它,因为它有一个Mac桌面应用程序的示例项目。

i have searched a lot on the web but can not find the actual sample source code that can help me to get started for google chat implementation , the sample code provided with the xmpp framework also does not tell clearly about it, as it have a sample project of Mac desktop application.

我已经能够在xmppframework中提供的示例项目(iphoneXmpp)的帮助下向所有在线/离线/离开的朋友展示,但它也是doest告诉我们如何发起聊天。

I have been able to show all my friends who are online/ofline/away with the help of sample project(iphoneXmpp) which is provided in the xmppframework, but it also doest tell anything about how to initiate a chat.

请提供任何示例源代码,以便我可以在我的应用中初始化Google聊天。

Please provide me any sample source code so that i can initialize the google chat in my app.

我真的被卡住了。

提前感谢

推荐答案

okey在查看xmpp框架的桌面应用程序并尝试将其包含在我的iphone应用程序中后,我没有放弃并有一些解决方案..

okey i didnt give up and had some solution after looking into the desktop application of xmpp framework and tried to include it in my iphone app..

这是在gmail上向我们的聊天朋友发送消息的代码..

here is the code to send message to our chat friend on gmail..

-(void)sendMessage
{
messageStr = [NSString stringWithFormat:@"%@",[msgField text] ];
//messageStr = [NSString stringWithString:@"hello ji....."];

BOOL isEmpty = [ self validateIsEmpty:msgField.text];
if([messageStr length] > 0 && isEmpty == NO )
{
    NSXMLElementK *body = [NSXMLElementK elementWithName:@"body"];
    [body setStringValue:messageStr];

    NSXMLElementK *message = [NSXMLElementK elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:[[user jid] full]];
    [message addChild:body];
            [[self xmppStream ] sendElement:message];
}

在didReceiveMessage中,我有以下代码......

and in didReceiveMessage , i have following code...

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{

NSLog(@"---------- xmppStream:didReceiveMessage: ----------");

NSLog(@"--jid---%@", [[user jid] full]);
NSLog(@"--from----%@", [message from]);
//if(![[[user jid] full] isEqual:[message from]]) return;// important when chatting with 2 or more .. and receiving 2 or more messages...

if([message isChatMessageWithBody])
{
    NSString *msg = [[message elementForName:@"body"] stringValue];

    NSLog(@"mmmmmmmmmmssssssgggg-%@",msg);

    [str appendString:[NSString stringWithFormat:@"%@:%@\n\n", [message from], msg]];
    [chatBox setText:str];
}
}

我可以使用发送/接收聊天这两种方法但问题在于,有时我从可用在线联系人的表格视图(我们可以与谁聊天)中选择的人的身份证不会收到该消息,但任何其他人都会收到该消息..

i'm able to send/recieve the chat using these two methods but problem is that some times the person's id which i selected from the table view of available online contacts(to whom we can chat with) does'nt receive the message but any other person receives the message..

干杯!!

这篇关于如何在iPhone应用程序中实现谷歌聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆