I am developing Chat Application using XMPPFramwwork in iPhone.I successfully completed one to one chat,now i want to develop multiuser chat in my application.
I tried the fallowing code but any delegate methods of XMPPRoomDelegate are not called.how can i start to create chat room.When and how the roomdelegate methods get called....any reply thanks inadvance.
XMPPStream *xmppStream = [[XMPPStream alloc] init];
XMPPRoomCoreDataStorage *xmppRoomStorage = [XMPPRoomCoreDataStorage sharedInstance];
XMPPJID *roomJID = [XMPPJID jidWithString:#"vvreddy50#gmail.com"];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
Two problems:
XMPPFramework is mostly asynchronous. That means you need to call -fetchConfigurationForm after you've authenticated, in your -xmppStreamDidAuthenticate: method.
If those two calls need to be made in sequence, then call -configureRoomUsingOptions in -xmppRoom:didFetchConfigurationForm:.
Nothing at all will happen unless you call -connect: on the stream. Make sure to implement -xmppStreamDidConnect: and initiate authentication with the server in that method.
Related
I'm creating a Chat application, i have done one-to-one chat, but unable to approach how to create chatRoom and add people.
I think this link will give you call the necessary information:
http://xmpp.org/extensions/xep-0045.html.
In simple terms varying the resource while logging in to the server allows multiple users to be affiliated to a single login i.e. the single login does the work of a chat room.
You can easily create group for group chat.
Use below function for create group
-(void)joinMultiUserChatRoom:(NSString *)RoomName
XMPPRoomHybridStorage *xmppRoomStorage1 = [XMPPRoomHybridStorage sharedInstance];
XMPPJID *chatRoomJID = [XMPPJID jidWithString:RoomName];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage1 jid:chatRoomJID];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:#"history"];
[history addAttributeWithName:#"maxstanzas" stringValue:#"1"];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user history:nil];
I have created new room for group chat by using this-
XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:#"viratsroom#conference.praveens-mac-mini.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self appDelegate] xmppStream]];
if ([xmppRoom preJoinWithNickname:#"viratsRoom"]) {
NSLog(#"room created");
[xmppRoom joinRoomUsingNickname:#"viratsroom11" history:nil];
}
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];
Room is getting created but with error
I have traced at server side and found this error-
"presence xmlns="jabber:client" from="viratsroom#conference.iisd09/arup" to="arup#iisd09/ClientXMPP" type="error" error code="404" type="wait" recipient-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"
Room wasnt configured properly hence all errors
calling this immediately after creating room doesnt work-
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
it takes a little time to create room after that u can configure the room.
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:2];
Thanks
I'm trying for group chat in iphone,am able to use single chat successfully.
I have created new room using following code successfully.
XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:#"viratsroom#conference.praveens-mac-mini.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self appDelegate] xmppStream]];
if ([xmppRoom preJoinWithNickname:#"viratsRoom"]) {
NSLog(#"room created");
[xmppRoom joinRoomUsingNickname:#"viratsroom11" history:nil];
}
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];
now under users in this group there is one user shown on openfire server which is correct.
my questions are,
1)where and how to handle invitation message to join group?
2)I have tried to join the same group made above by using following code
XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:#"viratsroom#conference.praveens-mac-mini.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self appDelegate] xmppStream]];
[xmppRoom joinRoomUsingNickname:#"viratsroom11" history:nil];
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];
the room name now is shown in my offline users list.
now users under this room on openfire server should increase to two as one more user has joined this room but it still shows only one previous user member.
Am I missing something? any mistake in code ? please help!
Thanks .
I got this,
Room wasnt configured properly hence all problems
calling this immediately after creating room doesnt work-
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
it takes a little time to create room after that u can configure the room.
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:2];
:)
I receive messages from a Google Talk account, they are shown in the Table View in the Ios emulator, but when i send it, it is not shown in the Google Talk client (in another computer). This is the code:
-(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 name#gmail.com)
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
self.mensaje.text=#"";
}
As I say, messages are received perfectly, but I cannot send. Ive seen plenty of examples of how to send, and they are like my code. If i debug sender it is shown ok (namesender#gmail.com), and the "to" attribute is ok too (namereceiver#gmail.com). The xmppStrem is set correctly (as far as i know):
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
In ViewDidLoad method.
Any help? Thank you.
---EDIT---
I forgot to say, both accounts know each others and in the Google Talk client, the presence is sent.
I found the answer. I had two classes receiving messages, because Class A must receive a message to trigger the pushing of the view of the class B (this app is unable to start a chat conversation by itself). So, i set two xmppStream, one for every class. I put an xmppStream in my General class, make both classes take that xmppStream, and it now sends messages.
I'm trying to understand how to use ASIHTTPRequest to initiate a long-running file download from the internet that can be continued if the user switches to other apps using multi-tasking.
So far I was able to keep downloading the file within the app, as the user switches tabs, etc, but once the home key is pressed, the request appears to be cancelled. Is there a way to use the ASIHTTPRequest or ASINetworkQueue to download files in background?
Here's what I currently have:
//the requests are created like this
self.backgroundMovieDownloader.request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:self.video.url]];
//the requests are added to this queue
if (!self.networkQueue) {
self.networkQueue = [[ASINetworkQueue alloc] init];
}
self.failed = NO;
[self.networkQueue reset];
//[self.networkQueue setDownloadProgressDelegate:progressIndicator];
[self.networkQueue setRequestDidFinishSelector:#selector(videoFetchComplete:)];
[self.networkQueue setRequestDidFailSelector:#selector(videoFetchFailed:)];
[self.networkQueue setShowAccurateProgress:YES];
[self.networkQueue setDelegate:self];
[self.networkQueue go];
You need to add this line to allow it to run in the background
self.backgroundMovieDownloader.request.shouldContinueWhenAppEntersBackground = YES;