2012-06-19 103 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