Presence with user id XMPP Framework - xmpp

How can i get presence of any specific user with user id.
I mean to say without add that user in roster list.
Please help me regarding this.
Thanks in advance.

I assume you're talking about the iOS XMPPFramework. If not, please ignore this answer.
You can send a directed presence to another user like this:
XMPPPresence *presence = [[XMPPPresence alloc] initWithType:#"probe" to:someJid];
[_xmppStream sendElement:presence];
Where _xmppStream is a open and connected XMPPStream.
Notice however, that most XMPP Servers will not allow reply to this kind of directed presences if the other user is not in your roster. If you're managing your own XMPP server, you can modify it to allow this kind of operations.

You can ask for any users presence by making call of following plugin url
http://{SERVER_NAME}:9090/plugins/presence/status?jid=USERID#SERVER_NAME&type=text
EX:
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://SERVER_NAME:9090/plugins/presence/status?jid=ANYUSER#SERVER_NAME&type=text"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if(connectionError==nil)
NSLog(#"plugins response ===%#",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}];
It will return "online" foractive users and "unavailble" for offline users.Please take care about the server setting on openfire server shown in image.

Related

Facebook iOS SDK 3.0, implement like action on a url?

I'm trying to implement Like via the facebook open-graph-api with the Facebook iOS SDK 3.0.
Everything seems to work except the FbGraphObject and that's because I have no idea how it should look because this clearly does not work.
What I'm trying to do is to like a url posted as an object. A simple Like with via the open-graph.
The error message I get the the code below is:
The action you're trying to publish is invalid because it does not specify any
reference objects. At least one of the following properties must be specified: object.
The code I use is this:
FBGraphObject *objectToLike = [[FBGraphObject alloc]initWithContentsOfURL:[NSURL URLWithString:facebookLike.titleLabel.text]];
FBRequest *requestLike = [[FBRequest alloc]initForPostWithSession:[FBSession activeSession] graphPath:#"me/og.likes" graphObject:objectToLike];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:requestLike
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
if (!error &&
result) {
DLog(#"NothingWentWrong");
}
DLog(#"MajorError: %#", error);
}
];
[connection start];
UPDATE:
Checked some more info and my guess it to use this method:
https://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBGraphObject/#//api/name/graphObject
To somehow create an object. It's the graphObject method that I probably need to do something with. Any help at all would be appreciated.
I've actually manage to create a simple and quite dirty solution of this.
The solution does not seem optimal but it's currently a working solution.
If anybody has used the explorer tool on facebook on this url:
https://developers.facebook.com/tools/explorer/
You know how the URL will look like when facebook is sharing a like. It has to have the URL and an access-token.
So my solution became just to disregard sending anything from the Facebook SDK and just send a post request to the same URL that I've used in the explorer tool.
There seems to be some referencing to it on the facebooks docs if you look closely and deep, but no one explains exactly how to actually make the connection, so this is my solution:
NSString *urlToLikeFor = facebookLike.titleLabel.text;
NSString *theWholeUrl = [NSString stringWithFormat:#"https://graph.facebook.com/me/og.likes?object=%#&access_token=%#", urlToLikeFor, FBSession.activeSession.accessToken];
NSLog(#"TheWholeUrl: %#", theWholeUrl);
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:#"POST"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(#"responseData: %#", content);
If you look at the code I just take the url and puts two dynamic strings in the url, one with the object-url and one with the access token. I create a URLRequest and make it a POST request, and the response from facebook gets logged so one actually can see if the like go through or not.
There might be some performance improvements that can be done with the actual requests but I will leave it up to you if you see any slowdowns.
I'm still interested in other solutions but this is the one I will use for now.
We don't currently support Like through our Graph API.
What you can look through is something like this :
https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
I’m not sure what initWithContentsOfURL does, but from the name I guess it tries to actually load content from a given URL(?).
You only have to give the URL as a text parameter – a URL is what represents an Open Graph object. Facebook will do the rest, scraping the page behind that URL and reading it’s OG meta tags, etc.
Maybe just this?
FBRequest *requestLike = [[FBRequest alloc]initForPostWithSession:[FBSession activeSession]
graphPath:#"me/og.likes"
graphObject:[NSURL URLWithString:facebookLike.titleLabel.text]];

Network push notification

I am wondering if there is a simple way to push a notification, to all your users currently using your application.
So the next time they launch the application and they are connected to Wi-Fi, they receive a alert telling them that, i.e., "An update is available".
EDIT:
To explain in greater detail what I am looking for. I am developing an application that should only be used when it is the most recent version of the software, so I would like to be able to send out a message (notification) for when an update is available in the AppStore. This is seen in some games such as AngryBirds and Cut the Rope.
Maybe even change a BOOL in the code to TRUE, leaving a red flag if{} BOOL is TRUE. (Of course first I'd like an answer to the more basic version. This would be helpful though as well)
Hope this clears things up.
With regards,
SirKaydian
Local Notification Solution
Essentially what Oscar said previously, you could make this really simple. If you wanted to check after every launch of the application you could easily call some sort of local API (or similar) call from your application to a web service you might host. So for example you have a PHP file:
<?php
$currentVersion = 1.3;
echo $currentVersion;
?>
That simple PHP script can be updated by you whenever you release an update. The iPhone can recognize this by querying that PHP file on every startup (check NSURLConnection delegate methods to get the response from any particular URL). Now from previous checks by your application it can store those in an NSUserDefaults value by the following:
NSUserDefaults *defaults = [[NSUserDefaults alloc] init];
NSString *loadedVersion = [defaults valueForKey:#"MYAPP_CURR_VERSION"];
Now we need to compare the two from your NSURLConnection delegate method that receives the string back from the PHP file on your web service.
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://www.website.com/folder/version.php"]];
[urlRequest setHTTPMethod:#"GET"];
[urlRequest setHTTPBody:[postParams dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];
[connection start];
The above code will send the request to your server URL that you tell it to. Now when we get the response we'll do it like this:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSString *responseVersionFromServer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(![loadedVersion isEqualToString:responseVersionFromServer]) {
//execute code here to show a local notification or UIAlertView
}
}
That will do all the comparison for you.
NOTE: You must add NSURLConnectionDelegate in your .h Header file!
Push Notifications Solution
There are services out there for allowing your application to have push notifications such as Urban Airship that you can log into and send a push notification to all of your users when an update becomes available. It's really simple to use, check out their website. (www.urbanairship.com)
You could consume a webservice and compare versions of your app (maybe save the version to NSUserDefaults), I'm sure there are other solutions but this one comes to mind. You could show an alert that links to the app store if the versions are different.

Response for Registering on Wordpress Site through iPhone

I am writing an app that displays content from a Wordpress Site, and also allows reading of comments as well as posting comments. I am handling logging in to leave a comment and posting a comment via XML-RPC. All that is working quite well. However, this particular site does not allow anonymous commenting. So, I need to allow Registering for an account through the app.
Currently, I take the desired "username" and "email" and submit via POST as follows:
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:#"http://www.lamebook.com/wp-signup.php"]];
[request setPostValue:#"example" forKey:#"user_name"];
[request setPostValue:#"example#test.com" forKey:#"user_test"];
[request setDelegate:self];
[request setDidFinishSelector:#selector(registerFinished:)];
[request setDidFailSelector:#selector(registerFailed:)];
[request startAsynchronous];
This works in that it will create the account. However, my issue is that in my registerFinished method:
- (void)registerFinished:(ASIFormDataRequest *)request {
NSString *response = [[NSString alloc] initWithData:[request responseData] encoding:NSASCIIStringEncoding];
NSLog(#"response %#", response);
}
The response is simply the HTML of the registration page. The HTML contains no information about the success or failure of the registration.
When using the webform the returned HTML has entries if any error occurred, for example:
<p class="error">Username must be at least 4 characters</p>
However, I do not seem to get these elements in the HTML I receive on the phone. Is there a proper way to do registration on the phone?
If you have access to the site, which I guess you do, you should be able to write a small plugin that let's you perform the registration by posting data to an URL specified by your plugin. This would be fairly simple, just hook up a function to the init action and check for the $_POST variable for any input.
Then simply use username_exists to check for existing users and wp_create_user to perform the registration. These functions will give return values that you in turn can send as a JSON reponse (or whatever is appropriate) back to you application.
In fact, my experience with XML-RPC is that it's somewhat limited, and not really up to date with the rest of WordPress, so I often make these little mini API's to handle situations like this. All that might have changed in the latest releases, however.

Newsletter and registration on iphone

I'd like to know if it was possible, if a user wishes to subscribe to updates of my applications, take a form that is automatically subscribed to this newsletter at this address http://www.gseo.it/lists/?p=subscribe&id=2 (this is my mailing list with double opt in) but I'd like to know that a user can subscibe this newsletter directly from my iphone app.
Thanks
You could do an HTTP POST to that form using ASIFormDataRequest.
This isn't working code, but it might look something like:
NSURL *url = [NSURL URLWithString:#"http://www.gseo.it/lists/?p=subscribe&id=2"];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:#"someone#example.com" forKey:#"email"];
[request startSynchronous];
You can get the library here.
Yes of course you can, open up a UIWebview with the the url provided. Don't forget that this may look not good in the iphone browser so providing a custom html code depending on the user agent may improve things.

Has anyone implemented the PayPal API through a native iPhone app?

It seems the only way to stay "in app" is to give them a UIWebView of the paypal mobile site and let them complete the transaction there, otherwise the user would need to use their API key.
Does this sound right and has anyone got or seen any sample code? I have to think this is a common piece of code.
UPDATE:
Will Apple allow this?
It is a charity app, so I am assuming there is no issue.
Re-UPDATE:
I assumed wrong.
Apple will not allow payments directly within apps using paypal. You have to re-direct to a web interface.
Re-Update:
As answered below this code may still be useful for the purchase of physical goods
Update:
Although this code works, App Store terms won't allow you to use this code within an app.
Original Answer:
I figured this out after some heavy API research. Below is a method that creates an HTTP POST to send to Paypal and makes an NSURLRequest. You can fill in the appropriate string format variables. I used HTTP Client to check what I was doing.
- (void)sendPayPalRequestPOST{
perfomingSetMobileCheckout=YES;
recordResults = FALSE;
NSString *parameterString = [NSString stringWithFormat:#"USER=%#&PWD=%#&SIGNATURE=%#&VERSION=57.0&METHOD=SetMobileCheckout&AMT=%.2f&CURRENCYCODE=USD&DESC=%#&RETURNURL=%#", userName, password, signature, self.donationAmount, #"Some Charge", returnCallURL];
NSLog(parameterString);
NSURL *url = [NSURL URLWithString:paypalUrlNVP];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [parameterString length]];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection ){
webData = [[NSMutableData data] retain];
[self displayConnectingView];
}else{
NSLog(#"theConnection is NULL");
}
}
After this you need to parse the response, grab the session key and create a UIWebView to take them to the mobile paypal site. Paypal lets you specify a "return URL" which you can make anything you want. Just keep checking the UIWebview in the delegate method for this address and then you know the transaction is complete.
Then you send one more HTTP Post (similar to the one above) to Paypal to finalize the transaction. You can find the API information in the Paypal Mobile Checkout API docs.
Apple will allow custom checkouts for physical purchases. I talked with them at the iPhone Tech Talks in London and they said that they will not support physical purchases with In App Purchase as they would have to deal with refunds, etc. They also referred to existing apps that have custom checkouts.
When you say "I assumed wrong" about Apple allowing charitable donations within an app, can you provide any more information? I'm working on an app and there's a requirement to allow charitable donations...I haven't been able to find anything from Apple strictly forbidding it, but I haven't been able to find an app that allows charitable donations in the store, either.
(I struggled with whether to post this here and not as a new top-level question, but you're the first person I've come across with direct knowledge about the charitable giving within an iPhone app question).
Is it not possible using Paypal's Mobile Payment Library?
https://www.x.com/community/ppx/xspaces/mobile/mep?view=overview
Depending on the complexity of your needs, PayPal's iOS SDK (released March 2013) might be the ticket.