2012-06-19 135 views
0

我接收来自Google Talk帐户的消息,它们显示在Ios仿真器的表视图中,但是当我发送它时,它不显示在Google Talk客户端(在另一台计算机中)中。这是代码:XMPPFramework消息未发送

-(IBAction)sendchat:(id)sender 
{ 
General *general = [General sharedManager];//It is a singleton class used to store some values that need to be accesible in the whole application. 


NSXMLElement *body = [NSXMLElement elementWithName:@"body"]; 
text=[mensaje text]; 
NSLog(@"Texto en el body: %@", text); 
[body setStringValue:text]; 
NSArray *dest=[general.firstfrom componentsSeparatedByString:@"/"];//in firstfrom is stored the account from wich we receive the first message. This app cannot start a conversation itself, must only answer 

NSLog(@"Destination trimmed: %@", [dest objectAtIndex:0]);//Here, the destination account shows correctly (without the /xxxx stuff, just [email protected]) 
XMPPMessage *mens=[[XMPPMessage alloc]init]; 
[mens addAttributeWithName:@"body" stringValue:text]; 
[mens addAttributeWithName:@"sender" stringValue:general.userlogin]; 
NSLog(@"text vale: %@", text); 
NSXMLElement *messagetosend = [NSXMLElement elementWithName:@"message"]; 
[messagetosend addAttributeWithName:@"type" stringValue:@"chat"]; 
[messagetosend addAttributeWithName:@"to" stringValue:[dest objectAtIndex:0]]; 
[messagetosend addChild:body]; 
NSLog(@"We are sending to: %@", [dest objectAtIndex:0]); 
[self.xmppStream sendElement:messagetosend]; 

[self xmppStream:xmppStream didReceiveMessage:mens];//manage the sent message as it was received, to show it in the Table View 
[email protected]""; 
} 

正如我所说,邮件接收完美,但我不能发送。我见过很多关于如何发送的例子,他们就像我的代码。如果我调试发件人,它显示ok([email protected]),并且“to”属性也可以([email protected])。 xmppStrem设置正确(据我所知):

xmppStream = [[XMPPStream alloc] init]; 
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; 

在ViewDidLoad方法。

任何帮助?谢谢。

---编辑---

我忘了说,这两个帐户知道对方,并在谷歌Talk客户端,存在被发送。

+0

没有人可以帮助我吗? :( – Fustigador

+0

你应该检查jid值..我不记得但我认为他们不同于emailID。 – harshalb

+0

嗨,你可以请指导我如何添加XMPPFramework,我GOOGLE了,但链接给404错误..一些XMPPFrameworks我下载了像iPhoneXMPP,但它给错误..请指导我@Fustigador – Babul

回答

1

我找到了答案。我有两个类接收消息,因为A类必须收到一条消息才能触发推送类B的视图(此应用无法单独开始聊天对话)。所以,我设置了两个xmppStream,每个类都有一个。我在我的General类中放了一个xmppStream,让这两个类都接受了这个xmppStream,现在它发送消息。

+0

一些代码示例可以帮助很多!:) –

+0

@Fustigador我面临同样的问题,当我发送消息发送元素的方法是不calling.but在登录时间,它是完美调用..请帮助我 –

+0

我想帮助你,但自从我使用xmppFramework以来,这已经很长时间了。 – Fustigador