I am developing a chat application in iphone using XMPPFramework. Everything is working great but stuck at the point. I want to retrieve a list of all public rooms but there is no method found in XMPPFramework. So can someone help me out to solve this issue?
Here is the code to get list of all room
NSString* server = #"chat.shakespeare.lit"; //or whatever the server address for muc is
XMPPJID *servrJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:#"get" to:servJID];
[iq addAttributeWithName:#"from" stringValue:[xmppStream myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[xmppStream sendElement:iq];
If you have code to get the room of specific user please share it
I use this code to query server directly, but I'm not sure that is the best way.
XMPPIQ *iq = [[XMPPIQ alloc] initWithType:#"get"];
NSString* conferenceHost = [NSString stringWithFormat:#"conference.%#", _xmppStream.hostName];
[iq addAttributeWithName:#"from" stringValue:conferenceHost];
[iq addAttributeWithName:#"to" stringValue:_host];
DDXMLElement *query = [DDXMLElement elementWithName:#"query" xmlns:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[_xmppStream sendElement:iq];
Hope this help someone.
By the way, if you adopt this solution, then you have to do some parse in delegate method:
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
}
I thing the best way is to parse method once the connection has started:
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {
/* parse */
}
Then you check
[[sender] from] domain]
if contains "conference." then you can think that sender is a room and finally you can add to NSMutableArray, for instance.
Also when a new room will be created, didReceivePresence will be called, so parser will add the new room.
So, you have:
NSMutableArray* rooms;
Your method will be:
-(NSMutableArray*)getRooms {
return _rooms;
}
Related
XMPPFarmework us openfire
How to obtain XMPP chat room list in iOS ?
Anyone please show me a way to solve out this.Thanks!
Below code works for us when connected to an ejabberd server on Amazon EC2 and hope it should work for Openfire too.
- (void) getChatRooms:(XMPPStream *)stream
{
NSString* server = #"conference.myserver.com";
XMPPJID *servrJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:#"get" to:servrJID];
[iq addAttributeWithName:#"id" stringValue:#"chatroom_list"];
[iq addAttributeWithName:#"from" stringValue:[stream myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[firstStream sendElement:iq];
}
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
DDLogVerbose(#"%#", [iq description]);
}
I am developing chat application using xmpp client. I can send and receive message when I login with one account. My problem is when i login with two different account i cannot send message using First login account. For sending message i tried the fallowing code:
- (void)sendMessage:(id)sender
{
xmppStream=[[self appDelegate] xmppStream];
NSString *messageStr =messageField.text;
if([messageStr length] > 0)
{
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:jidStr];
[message addChild:body];
NSLog(#"%#",message);
}
}
In this delegate method, i create stream object like fallowing
-(void)setUpStream
{
XMPPStream *xmppStream=[XMPPStream alloc] init]
}
when i second time login with another account then xmppStream object is associated with second account but not for First account.
so i can't send message using first account.can any one solve my problem plz and how to create two xmppStream objects for two accounts;
The easiest way to do this is to create to xmppStream objects in your AppDelegate.
Call one xmppStreamOne and xmppStreamTwo.
You could even create an NSMutableArray of xmppStreams if you intent to log into many different different servers.
When you retrieve the xmppStream from the AppDelegate make sure to grab the right one.
I am developing a XMPP based chat application for iOS. One of the features of the app is that i need to block some of the users from my rooster.Is there any method available to this in the XMPP framework ? If not, is there some work around to do this ?
Also can some one help me in sending images from one user to other using XMPP ?
There are a number of things you might want to consider:
Likely your user is subscribed to the contact's presence and vice-versa. He will unsubscribe from the contact's presence (so he will no longer receive presence notifications from him) by sending:
<presence to='contact#example.com' type='unsubscribe'/>
He will revoke subscription to his own presence from the contact by sending:
<presence to='contact#example.com' type='unsubscribed'/>
Finally you can remove the item from your roster.
<iq from='user#example.com/home' type='set' id='roster'>
<query xmlns='jabber:iq:roster'>
<item jid='contact#example.com' subscription='remove'/>
</query>
</iq>
In fact, if you send the stanza above, i.e. if you want to cancel both subscriptions, you do not need to send the presence stanzas, they will be handled by the servers.
Finally, you can now block further interaction with the user by means of the jabber:iq:privacy API. This is explained in detail here.
The general presence/roster management is explained in the same rfc, probably best here.
Please check this code to implement user blocking:
-(void)blockUser{
XMPPIQ *iq = [[XMPPIQ alloc]init];
NSString *from = [NSString stringWithFormat:#"from#mail.com/resources"];
[iq addAttributeWithName:#"from" stringValue: from];
[iq addAttributeWithName:#"type" stringValue:#"set"];
NSXMLElement *block =[NSXMLElement elementWithName:#"block" xmlns:#"urn:xmpp:blocking"];
NSXMLElement *item = [NSXMLElement elementWithName:#"item"];
[item addAttributeWithName:#"jid" stringValue:#"to#mail.com/resources"];
[block addChild:item];
[iq addChild:block];
[xmppStream sendElement:iq];
}
- (void)setupXMPPPrivacy
{
NSLog((#"%s [Line %d] "), __PRETTY_FUNCTION__, __LINE__);
//Init XMPPPrivacy List
//xmppPrivacy = [[XMPPPrivacy alloc] init];
xmppPrivacy = [[XMPPPrivacy alloc] initWithDispatchQueue:dispatch_get_main_queue()];
//Activate xmpp modules
[xmppPrivacy activate:[[self appDelegate] xmppStream]];
//Delegate XMPPPrivacy
[xmppPrivacy addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppPrivacy retrieveListWithName :#"Block_List"];
}
-(void)privacyblock
{
[xmppPrivacy retrieveListWithName:#"Block_List"];
[xmppPrivacy setActiveListName:#"Block_List"];
NSXMLElement *privacyElement = [XMPPPrivacy privacyItemWithType:#"jid" value:xmpp_jid action:#"deny" order:1];
[XMPPPrivacy blockIQs:privacyElement];
[XMPPPrivacy blockMessages:privacyElement];
[XMPPPrivacy blockPresenceIn:privacyElement];
[XMPPPrivacy blockPresenceOut:privacyElement];
NSLog(#"-------> PRIVACY ELEMENT: %#", privacyElement);
[arrayPrivacy addObject:privacyElement];
[xmppPrivacy setListWithName:#"Block_List" items:arrayPrivacy];
}
Is there any way to detect last caller number & call duration on iPhone, I am able to get all notification (Core Telephony) but don't know how to get caller number.
You can't, the API will not allow you to do this.
I think apple will never allow this due to privacy concerns.
According to api you cant do it... but here something which might help you ... though I haven't tried it myself...
http://iosstuff.wordpress.com/2011/08/19/accessing-iphone-call-history/
Apple officially don't allow.You cann't access the database of the other application then your one.
You can use this
if ([name isEqualToString:#"kCTCallIdentificationChangeNotification"])
{
// CTCallCenter *center = [[CTCallCenter alloc] init];
// center.callEventHandler = ^(CTCall *call) {
// NSLog(#”call:%#”, [call description]);
// };
//NSDictionary *info = (NSDictionary *)userInfo;
CTCall *call = (CTCall *)[info objectForKey:#"kCTCall"];
NSString *caller = CTCallCopyAddress(NULL, call);
NSLog(#"caller:%#",caller);
//CTCallDisconnect(call);
/* or one of the following functions: CTCallAnswer
CTCallAnswerEndingActive
CTCallAnswerEndingAllOthers
CTCallAnswerEndingHeld
*/
//if ([caller isEqualToString:#"+1555665753"])
if ([caller isEqualToString:#"+918740061911"])
{
NSLog(#"disconnecting call");
//disconnect this call
CTCallDisconnect(call);
}
}
I'm trying to make an iPhone app where a user can use a built-in template for sending SMS messages. For example:
Dear [recipient name]
I would like to meet you.
Yours sincerely,
[recipient name]
I want to change [recipient name] to the person the user is sending the SMS message to.
How would I generate the string to be sent in the SMS message, and how would I send it?
if any one looking for the code i have done it myself.
if (appdelegate.dataarray.count>0) {
NSMutableArray *dataarrrr = [appdelegate.dataarray objectAtIndex:0];
NSLog(#"%#",[dataarrrr objectAtIndex:0]);
NSString *aa = [dataarrrr objectAtIndex:0];
NSMutableArray *myArray = [aa componentsSeparatedByString:#","];
NSString *n = [myArray objectAtIndex:0];
NSString *m=[myArray objectAtIndex:1];
NSString *Message = [dataarrrr objectAtIndex:1];
NSString *new = [Message stringByReplacingOccurrencesOfString: #"<Dear User>" withString:n];
controller.body = new;
controller.recipients= [NSArray arrayWithObject:m];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
See the MFMessageComposeViewController, you can set the SMS body before displaying the message composer. I don’t think there’s a better way to send text messages, see this related question.