iOS GET Twitter & Parse.com - Authorisation Method - xcode

I am developing an app for iOS. The app is to store the tweetIDs of the tweets the user has made which include another twitter handle in.
I can successfully log a user into a twitter account on the device through the Social Framework and call the API to receive and page through past tweets. However this takes up a lot of bandwidth on the device & I would prefer for the server (Parse.com) to do this for me, as it is here where the IDs will be stored. Is the social framework enough for this or do I need to create a Oauth from scratch for Java SDK for coding the parse server?
Thanks
D

NSString * requestString = [NSString stringWithFormat:#"https://api.twitter.com/1.1/users/show.json?screen_name=%#", user.username];
NSURL *verify = [NSURL URLWithString:requestString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:verify];
[[PFTwitterUtils twitter] signRequest:request];
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
You pass in the username of the user you want to authenticate for. Then create an NSDictionary object and use the 'NSJSONSerialization JSONObjectWithData:options: method with the NSData data object that you get from the request to be able to use the results of the response. Happy coding.

Related

How should one handle NSURLAuthenticationMethodXMobileMeAuthToken?

We're using a NSURLSessionDataDelegate and have the following delegate method implemented:
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler { ... }
Frequently we find that users of iCloud receive a NSURLAuthenticationMethodXMobileMeAuthToken challenge. Sending back a rejection doesn't work (as the server won't try another challenge) and sending back an acceptance with
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
doesn't work either.
What are we supposed to do with this authentication challenge type? Has anyone else seen it?
For any protection space that you aren't explicitly handling, or for any credential type that you don't understand, you should typically use NSURLSessionAuthChallengePerformDefaultHandling (the credential is ignored, but typically pass nil) to tell the OS to handle the credential as though you didn't provide an authentication delegate method.

"push notifications at least one user should be subscribed for APNS" Quickblox

Hi I have an issue here with regards to sending Push Notifications from my app. I can send them from the admin panel and they are received by the device but not from device to device. I have re-uploaded both development and production certificates on a couple of occasions now. Also push notifications can only be sent from the admin panel in the sandbox environment (no errors) and not the production environment (No recipients. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API). Can someone help please?
//
NSString *message = #"Testing APNS!";
NSMutableDictionary *payload = [NSMutableDictionary dictionary];
NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[aps setObject:#"default" forKey:QBMPushMessageSoundKey];
[aps setObject:message forKey:QBMPushMessageAlertKey];
[payload setObject:aps forKey:QBMPushMessageApsKey];
QBMPushMessage *pushMessage = [[QBMPushMessage alloc] initWithPayload:payload];
// Send push to user
[QBMessages TSendPush:pushMessage toUsers:self.opponent.login delegate:self];
//
[QBMessages TSendPush:pushMessage toUsers:self.opponent.login delegate:self];
You can's send push notification to user's login, you have to use user's ID
For example:
[QBMessages TSendPush:pushMessage toUsers:#"22,33,77" delegate:self];

In-app purchase issue with Mac app

I am doing in-app purchasing in Mac as well as iOS app.
What we have understood when a sandboxed environment receipt is validated against https://buy.itunes.apple.com/verifyReceipt we get the status code as 21007: CargoBayStatusSandboxReceiptSentToProduction.
This works perfectly in iOS, but for the Mac app the result is different.
I have a valid Sandboxed Environment receipt in my Mac app which I verified using the https://sandbox.itunes.apple.com/verifyReceipt.
When I verify the same receipt with https://buy.itunes.apple.com/verifyReceipt I need to get back the status code as 21007, but that is not happening. Instead, I get the following response:
<html><head><title>Error</title></head><body>Your request produced an error. <BR>[newNullResponse]</body></html>
Basically if I submit this app in Mac app-store for verification and the Apple guys use test IDs, I will get a sandbox receipt which will fail with status code for production URL receipt validation and then I can fall back to sandbox URL for receipt validation. But as described, the response does not contain a valid status code.
I have executed the following commands in the terminal:
Encode receipt using base 64 encoding, where receipt is the path of the receipt file:
base64 -i receipt
Post data to verify the receipt:
curl -d '{ "receipt-data": "<your b64 string here>" }' https://sandbox.itunes.apple.com/verifyReceipt
or
curl -d '{ "receipt-data": "<your b64 string here>" }' https://buy.itunes.apple.com/verifyReceipt
Response for production URL is :
<html><head><title>Error</title></head><body>Your request produced an error. <BR>[newNullResponse]</body></html>
Ideally it should be {status code = 210007}. Did anybody face this issue before? Or am I missing anything?
For implementing IAP in MAC app is same as in iOS with below change. You need to make binary file after adding below code in
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *receiptPath = [[[NSBundle mainBundle] appStoreReceiptURL] path];
// Test whether the receipt is present at the above path
if (![[NSFileManager defaultManager] fileExistsAtPath:receiptPath]) {
// Validation fails
exit(173);
}
}
This code will create receipt for your MAC. So, after it you can check IAP in your application. Please check that you are doing same.
A sandbox receipt is different from an iTunes receipt. You said the error hapens when you send your sandbox receipt to https://buy.itunes.apple.com/verifyReceipt. But this service is intended for iTunes store receipts. Don't mix them up.

Looking for OAuth version of Twitter code for iOS client

Am learning about iOS programming from book Head First iPhone Programming. In one exercise, they have sample code for Twitter which uses basic authorization. Now that Twitter uses OAuth, how can I get OAuth code so that I can test my client? Do I need to register my app with Twitter? How do I do that, since it's only a test app?
Here is the basic authorization version of the code; I'm looking for the OAuth version:
//TWITTER BLACK MAGIC
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://YOUR_TWITTER_USERNAME:YOUR_TWITTER_PASSWORD#twitter.com/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:[[NSString stringWithFormat:#"status=%#", themessage] dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSLog(#"%#", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
//END TWITTER BLACK MAGIC
To get Twitter oAuth access you will need to create app on http://dev.twitter.com and retrieve Consumer Key and Consumer Auth.
Perhaps this tutorial will help you:
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/

How to integrate Twitter support into an iOS application?

How to integrate Twitter support into an iOS application?
Stefan Arentz's Twitter library is a pleasure to use - it contains the views you need, there is basically no coding to do. Do register your app early with twitter and get a submission to request xAuth authentication permission so that you do not have to use the clumsy web-based oAuth method. With xAuth it is as simple as submitting username and password and keeping the returned authentication token to submit a tweet.
Here is an example:
Call -(void)sendTweet from your IBAction.
// Sending tweets from within the application
-(void)sendTweet {
// check if device capable of sending tweets
if([TWTweetComposeViewControllercanSendTweet])
{
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewControlleralloc] init];
[tweetSheet setInitialText:#"Twitting from my iSecret App"];
self.imageString = #"theSecret.png";
if(self.imageString) {
[tweetSheet addImage:[UIImageimageNamed:self.imageString]];
}
[selfpresentModalViewController:tweetSheet animated:YES];
}
else {
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:#"Sorry"message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"delegate:selfcancelButtonTitle:#"Ok"otherButtonTitles:nil];
[alert show];
}
}

Resources