回答
快速谷歌搜索显示许多XMPP libraries,无论是C/C++或ObjC。也许http://code.google.com/p/xmppframework/将是一个很好的起点,虽然我没有亲自尝试过。
下载XMPPFramework并解压缩。里面有几个文件夹。打开'Xcode'文件夹>打开'iPhoneXMPP'文件夹>点击'iPhoneXMPP.xcodeproj'>运行它。它首先要求登录凭证。成功登录后,它会显示你的好友列表。它适用于Gmail。有一个回调方法被称为为每个传入消息:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
user = [xmppRosterStorage userForJID:[message from] xmppStream:sender managedObjectContext:[self managedObjectContext_roster]];
if ([message isChatMessageWithBody])
{
NSString *body = [[message elementForName:@"body"] stringValue];
NSString *from = [[message attributeForName:@"from"] stringValue];
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:body forKey:@"msg"];
[m setObject:from forKey:@"sender"];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
NSLog(@"Applications are in active state");
//send the above dictionary where ever you want
}
else
{
NSLog(@"Applications are in Inactive state");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = @"Ok";
localNotification.applicationIconBadgeNumber=count;
localNotification.alertBody =[NSString stringWithFormat:@"From:"%@\n\n%@",from,body];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
//send the above dictionary where ever you want
}
}
}
要发送消息,我们必须写在任何你希望我们自己的方法:
-(void)sendMessage
{
NSString *messageStr =messageField.text;
if([messageStr length] > 0)
{
NSLog(@"Message sending fron Gmail");
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:messageStr];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:@"destination address"];
[message addChild:body];
NSLog(@"message1%@",message);
[[self appDelegate].xmppSream sendElement:message];
}
}
如果从Room/Group
发送消息然后使用此代码发送消息。
[xmppRoom sendMessage:@"Hi All"];
不需要通过xmppStream
发送消息。这一行代码完全适合我。
'@“Hi All”'存在'NSString'而不是'XMPPMessage'。不支持输入到sendMessage方法。您将收到此错误:发送'NSString *'到类型为'XMPPMessage *'的参数的不兼容指针类型 – 2014-06-11 07:58:02
Hi Keith OYS,对不起,我不知道您正在使用哪个XMPP库,但我确实在XMPPRoom类下进行了交叉检查。它的 - (void)sendMessage:(NSString *)msg; 我也使用过。让我知道如果我错了。 – 2014-06-24 08:36:15
最新的XMPPFramework使用' - (void)sendMessage:(XMPPMessage *)消息;'在'XMPPRoom'类中。因此,您需要首先初始化一个“XMPPMessage”。 – 2014-06-24 08:59:22
对于组发送消息/房间下面是摘录
XMPPMessage *message = [XMPPMessage message];
[message addBody:@"123"];
[self.currentRoom sendMessage:message1];
Where self.currentRoom is XMPPRoom
下面是通过XMPPFramework斯威夫特3
let user = XMPPJID(string: "[email protected]")
let msg = XMPPMessage(type: "chat", to: user)
msg?.addBody("Message to send")
self.xmppStream.send(msg)
- 1. XMPPFramework消息未发送
- 2. XMPPFramework:发送超时消息
- 3. 在XMPPFramework中发送消息
- 4. 如何使用Pika发送和接收RabbitMQ消息?
- 5. 发送和接收自己的消息
- 6. 消息队列发送和接收
- 7. 增强asio发送和接收消息
- 8. 发送和接收SOAP消息
- 9. 发送和接收Windows消息
- 10. 在两端发送和接收消息
- 11. 无法发送和接收XMPP消息
- 12. Android接收和发送消息
- 13. 连接消息接收和消息发送脚本
- 14. 如何在gcm和openfire之间发送和接收消息?
- 15. 使用Socket发送和接收消息的Android应用程序:
- 16. 使用Smack Api发送和接收消息Android的
- 17. Skype for Business Online - 使用UCWA发送和接收消息
- 18. 使用SSB在对话中发送和接收多条消息
- 19. 使用smack发送和接收消息API
- 20. 使用Cordova插件与Ionic发送和接收短消息
- 21. 发送和接收信息
- 22. 发送一条消息给iOS的XMPPFramework使用
- 23. 如何处理消息发送和接收
- 24. 如何在VB6和c#之间发送/接收Windows消息?
- 25. 如何在客户端发送和接收WebSocket消息?
- 26. 如何发送和接收广播消息
- 27. 如何在quickfix上发送和接收消息?
- 28. 如何在客户端发送和接收消息?
- 29. 对象用于发送消息或接收消息?
- 30. Lidgren不发送/接收数据消息
发送消息的解决方案,我敢肯定,XMPP框架有文档? – Pripyat 2011-02-28 08:26:53