manage friends using xmpp in iphone sdk? - iphone

Topic:
hi, i want to develop xmpp chat application, so far i have done with xmpp chatting, ie. sending and receiving messages to online users. but how can i add another online user as a buddy/friend ? and how can i remove friend from my friend list (using xmpp) ?? and how to know that someone has sent me a friend request (in xmpp)
Technology: iphone applcation programming
Language: Objective C

The XMPP server manages your buddy list (roster management), so you have to send the Subscribe/Unsubscribe packets to the XMPP server to add or remove buddies. Please see the section 8.2 in XMPP RFC (rfc-3921) for the format of XMPP message that you have to send and server response that you have to handle.
Here is the link to XMPP RFC (see section 8.2)
http://xmpp.org/rfcs/rfc3921.html

Use below code to send buddy request.Its working for me currently. username ot email id depends on your openfire settings.
XMPPJID *newBuddy = [XMPPJID jidWithString:#"friendsemailid or username"];
[xmppRoster addUser:newBuddy withNickname:nil];

1.You can add a new friend through this code in didReceivePresence delegate
else if ([presenceType isEqualToString:#"subscribe"])
{
NSXMLElement *presenceToRequest = [NSXMLElement elementWithName:#"presence"];
[presenceToRequest addAttributeWithName:#"type" stringValue:#"subscribed"];
[presenceToRequest addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"%#", [presence fromStr]]];
[presenceToRequest addAttributeWithName:#"from" stringValue:[NSString stringWithFormat:#"%#", [presence toStr]]];
[[self xmppStream] sendElement:presenceToRequest];
}
2.You can send friend request through XMPPRoster method
[xmppRoster addUser:[XMPPJID jidWithString:friendJID] withNickname:friendNickName];
3.In didReceivePresence delegate you can your friend request either you want to accept or reject a friendrequest.
I hope this information helps you to solve your issues.enter code here

Related

How to access all users using Rosters in XMPP ejabberd server

I am half way doing chat using XMPP. I have registered and logged in to ejabberd server.
I can see in web interface that there are 10 registered users and 4 online users. But Roster delegates not getting any contacts.
I have tried this solution. I did not get any results.
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
NSXMLElement *queryElement = [iq elementForName: #"query" xmlns: #"jabber:iq:roster"];
if (queryElement) {
NSArray *itemElements = [queryElement elementsForName: #"item"];
[ArrayUsers removeAllObjects];
for (int i=0; i<[itemElements count]; i++) {
NSString *jid=[[[itemElements objectAtIndex:i] attributeForName:#"jid"] stringValue];
[ArrayUsers addObject:jid];
}
}
return NO;
}
What may be the issue ? Do I have to configure the server settings for this to get contacts. It will be accessible to all by default?
Or, do i have to make a query to get the user details and automatically synced to CoreData storage.
Any help will be much appreciated.
The issue was that the shared roster module was not enabled in ejabberd configuration file. You can just enable mod_shared_roster in your ejabberd config modules section (the people who know how to do will understand. I personally dont know! So seeked help from others in the company).
Then, the shared Roster option will be available in the web interface of the admin side of ejabberd server.
Now configure the server to see all users to be seen for every body using the following link:
ejabbered configuration
Now, if you have logged in and set for automatic sync of Roster (XMMP framework by RobbieHanson Eg), you will get all users in the list.
Create a Shared Roster and get all users from the Roster. Check this

Open mail client of iPhone programmatically

In my application, if the user gave their gmail account then i am required to open the mail client with the gmail login credentials which comes when we select gmail option of mail programmatically but if that account is already stored in mail then i am required to redirect the user directly to their account. Can anybody pliz give me a glimpse of how i can achieve this programmatically.
You won't get that much control over the Mail app as all apps on the iPhone are sandboxed to prevent them from messing with Apple applications.
The only thing you can do (if you want to open the mail client to send an email), is something like this:
/* create mail subject */
NSString *subject = [NSString stringWithFormat:#"Subject"];
/* define email address */
NSString *mail = [NSString stringWithFormat:#"test#test.com"];
/* define allowed character set */
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
/* create the URL */
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:#"mailto:?to=%#&subject=%#",
[mail stringByAddingPercentEncodingWithAllowedCharacters:set],
[subject stringByAddingPercentEncodingWithAllowedCharacters:set]]];
/* load the URL */
[[UIApplication sharedApplication] openURL:url];
/* release the URL. If you are using ARC, remove this line. */
[url release];
Swift version of Léon Rodenburg's answer:
// define email address
let address = "test#test.com"
// create mail subject
let subject = "Subject"
// create the URL
let url = NSURL(string: "mailto:?to=\(address)&subject=\(subject)".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)
// load the URL
UIApplication.sharedApplication().openURL(url!)
Swift:
if let url = NSURL(string: "mailto://\(email)") {
UIApplication.sharedApplication().openURL(url)
}
I would suggest a much more improved answer.
The Slack.com mobile app does this, it detects common email clients listed on the device and shows a popup picker of 'which' email client you would like to open.
So to implement:
Google around to find the top 10 email clients (eg Mail, Google Inbox, OutLook, AirMail etc).
Get a list of installed apps on the phone either by searching all apps (but I am told you can now only find if an app is explicitly installed, so you will need detect the app).
Show a popup list if more than 1 email app is detected, requesting them 'which' app to open eg. Mail, Inbox.
This is the best solution I have seen working to date.

Direct Email to userid

I'm trying to send an email to a X person with some details in the app.
I'm using the following code. I don't want to use the MessageUI because I want to send mail directly without showing the mail composer.
NSString *url = [NSString stringWithFormat:#"mailto:pradeep#gmail.com?&subject=Results&body=Check Out your Results here=%#",score];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
But it fails with EXEC_BAD_ACCESS. Can anyone let me know how to solve it?
You can't send the mail without the mail composer. The way you are trying to do it will open the mail app and show the user the mail filed in with all the detail give in the mail link.
The only way to do what you want it to either have a webservice which handels the mail of implement SMTP in your app. You will need ask to user for there SMTP setting so a webservice might be the best way.

how can i send sms programmatically in iphone

I need to send sms programmatically.
I found sending programmatically email in google,But did n't found clear info regarding sending sms programmatically.
Can any one pls post some sample code.
Thank u in advance.
You can prompt the user to send a message with the number to send it to filled out, along with the body of the message, but you cannot send an SMS without the user completing the send.
Here is a perfect blog that can be used to send sms through application. SMS sending through application is introduced with iOS4.0 So you can not use MFMessageComposer in the previous versions of iPhone.
iOS 4 will be the minimum requirement.
hAPPY iCODING...
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSString *str=#"Your String for SMS"
picker.body=str;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Use this and add framework MessageUI.framework and call this function whenever you want to send message

How to send direct message with Twitter?

in my iphone application i have to send direct message throughout twitter,
the problem is that twitter had changed the authentication from basic authentication to oauth
and tutorial on the Web are out of date
so i use SAOauthTwitterEngine for the authentication part and all ok. but these classes don't use the api, so i have to use MGTwitterEngine for this.
the problem is that MGTE dont have oauth but only xauth and basic authentication, and i cant use this together anyone know how to do it? or know a tutorial that explain it.
thanks a lot.
i suggest you OAuth because xAuth requires you to send an email to twitter askeing them to give you the permission, and you have to write a reort on your application (this isn't good for a testing app)
have you tried this?
https://github.com/bengottlieb/Twitter-OAuth-iPhone
in my app I am sending direct messages to my twitter followers by using MGTwitterEngine let have a look:
appDelegate._engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
appDelegate._engine.consumerKey = kOAuthConsumerKey;
appDelegate._engine.consumerSecret = kOAuthConsumerSecret;
once you get authenticated this method get called
#pragma mark SA_OAuthTwitterControllerDelegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *)username {
NSLog(#"Authenicated for %#", username);
[appDelegate._engine sendDirectMessage:#"Test for Twitter direct message" to:username];
}
Hope this will help you.