我正在开发一个利用Robie Hanson s XMPPFramework的SOSMPP聊天机。
最重要的功能已经落实——发送和接收信息。 基本上,我已经建立了基本的实用聊天,当然很少见。
现在,我的问题是关于MUC。 我从其他网站看到的代码显示,initWithRoomName
载于XMPPRoom
。 然而,这种方法在被遮盖的头巾中是不存在的。 因此,除了此以外还有什么选择? 或者,如果没有,我如何利用XMPPFramework创建房间?
Thanks.
我正在开发一个利用Robie Hanson s XMPPFramework的SOSMPP聊天机。
最重要的功能已经落实——发送和接收信息。 基本上,我已经建立了基本的实用聊天,当然很少见。
现在,我的问题是关于MUC。 我从其他网站看到的代码显示,initWithRoomName
载于XMPPRoom
。 然而,这种方法在被遮盖的头巾中是不存在的。 因此,除了此以外还有什么选择? 或者,如果没有,我如何利用XMPPFramework创建房间?
Thanks.
下面是我如何解决自己的问题。 请注意,这一解决办法根本不涉及XMPPRoom。 首先,我制定了一种方法,根据情况,可以创造或进入一个房间。 (Per XMPP文件,XML关于创建的要求与你寄送进入房间的要求相同;即,如果该房间在你进入该房间时还不存在,该服务将为你创建。)
我们来到这里。 这是创造/进入房间的方法。 这种方法是向您打算创建/进入的房间派出人员。 如果你是第一个进入会议室,而该会议室尚未建立,你就自动成为房主和主持人。
- (void)createOrEnterRoom:(NSString *)roomName
{
//here we enter a room, or if the room does not yet exist, this method creates it
//per XMPP documentation: "If the room does not yet exist, the service SHOULD create the room"
//this method accepts an argument which is what you would baptize the room you wish created
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
NSString *room = [roomName stringByAppendingString:@"@conference.jabber.com/iMac"];
[presence addAttributeWithName:@"to" stringValue:room];
NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"50"];
[x addChild:history];
[presence addChild:x];
[[self xmppStream] sendElement:presence];
}
其次,在宣布XMPPStream方法的Appelegate中,我们通过检查服务器发送的状态代码,以欺骗前方法对XML的反应进行过滤。 如果地位法是201,本戈! 房间的设置只是罚款。 除201条外,其他地位法意味着不同的事物,但为了我们的目的,应侧重于201条。
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSXMLElement *x = [presence elementForName:@"x" xmlns:@"http://jabber.org/protocol/muc#user"];
for (NSXMLElement *status in [x elementsForName:@"status"])
{
switch ([status attributeIntValueForName:@"code"])
{
case 201: [self notifyRoomCreationOk:room];
}
}
}
Then, we tell the server that what we are creating a room of the type "instant," which means that we will send an IQ element telling it room defaults. notifyRoomCreationOk is a delegate method called in a different view when the room creation succeeds, after all I have to record the room in a text file to make it persistent so that the next time I open the app the room I created before will be visible. In my notifyRoomCreationOk method, I have sendDefaultRoomConfig which, basically, describes what is stated in the first sentence of this paragraph.
-(void)sendDefaultRoomConfig:(NSString *)room
{
NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"];
[x addAttributeWithName:@"type" stringValue:@"submit"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"http://jabber.org/protocol/muc#owner"];
[query addChild:x];
XMPPIQ *iq = [XMPPIQ iq];
[iq addAttributeWithName:@"id" stringValue:[NSString stringWithFormat:@"inroom-cr%@", room]];
[iq addAttributeWithName:@"to" stringValue:room];
[iq addAttributeWithName:@"type" stringValue:@"set"];
[iq addChild:query];
[[self xmppStream ] sendElement:iq];
}
确保你有XMPPStream能够就所谓的上述方法发表意见,否则这些方法就赢得了工作。 所有这一切都是如此。 Have!
XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"[email protected]/room" nickName:@"room"];
[room createOrJoinRoom];
[room sendInstantRoomConfig];
[room setInvitedUser:@"[email protected]"];
[room activate:[self xmppStream]];
[room inviteUser:jid1 withMessage:@"hello please join."];
[room sendMessage:@"HELLO"];
the user [email protected] should receive the invite message
Your post is old, however now I would do it like this:
- (void)createRoomWithJid:(XMPPJID*)roomJID
{
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.xmppRoomHybridStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user
history:nil
password:nil];
}
采用XMPPFRAMWORK,按以下代码设立聊天室。
let roomStorage: XMPPRoomMemoryStorage = XMPPRoomMemoryStorage()
/**
* Remember to add conference in your JID like this:
* e.g. [email protected]
*/
let roomJID: XMPPJID = XMPPJID.jidWithString("[email protected]")
let xmppRoom: XMPPRoom = XMPPRoom(roomStorage: roomStorage,
jid: roomJID,
dispatchQueue: dispatch_get_main_queue())
xmppRoom.activate(SKxmpp.manager().xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(SKxmpp.manager().xmppStream.myJID.user, history: nil, password: nil)
xmppRoom.fetchConfigurationForm()
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices for using SKPaymentQueue s restoreCompletedTransactions? Observations I know it s recommended to always ...
I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...
I have a UITextField that is a subview of a UITableViewCell. When my view loads, I want the text field to become first responder. I have a pointer to the text field in the table cell, so to do this I ...
I ve been working on adding in-app purchases and was able to create and test in-app purchases using Store Kit (yay!). During testing, I exercised my app in a way which caused the app to crash mid ...
In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...
Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...
I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...
Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...