我已经在网上搜索了很多,但无法找到实际的示例源代码,可以帮助我开始使用谷歌聊天实现,xmpp框架提供的示例代码也可以没有清楚地说明它,因为它有一个Mac桌面应用程序示例项目。如何在iphone应用中实现谷歌聊天
我已经能够在xmppframework中提供的示例项目(iphoneXmpp)的帮助下显示所有在线/离线/离开的朋友,但它也可以告诉任何有关如何发起聊天的信息。
请给我任何示例源代码,以便我可以初始化我的应用程序中的谷歌聊天。
我真的被卡住了。
在此先感谢
我已经在网上搜索了很多,但无法找到实际的示例源代码,可以帮助我开始使用谷歌聊天实现,xmpp框架提供的示例代码也可以没有清楚地说明它,因为它有一个Mac桌面应用程序示例项目。如何在iphone应用中实现谷歌聊天
我已经能够在xmppframework中提供的示例项目(iphoneXmpp)的帮助下显示所有在线/离线/离开的朋友,但它也可以告诉任何有关如何发起聊天的信息。
请给我任何示例源代码,以便我可以初始化我的应用程序中的谷歌聊天。
我真的被卡住了。
在此先感谢
好,我没有放弃,寻找到XMPP架构的桌面应用程序后,有一些解决方案,并试图把它列入我的iPhone应用程序..
这里是要发送消息给我们的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,我有以下代码...
- (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];
}
}
我能够发送/使用这两种方法收到聊天,但问题是,有时人的ID,我从可用的在线联系人的表视图中选择(我们可以聊天的人)不会收到消息,但任何其他人都会收到此消息。
干杯!
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message {
NSString *msg = [[message elementForName:@"body"] stringValue];
NSString *from = [[message attributeForName:@"from"] stringValue];
if (msg.length==0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiving Message"
message:[NSString stringWithFormat:@"From %@",from]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
if (msg.length!=0) {
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:msg forKey:@"msg"];
[m setObject:from forKey:@"sender"];
NSLog(@"message received : %@", m);
[_messageDelegate newMessageReceived:m];
}
}
这对你的伟大工程,它也会给你谁在发送消息的警报和谁愿意跟你聊天,不过我只是从我应该在哪里实施注销用户卡通过它我登录到iOS SDK。