How to upload photos to Plixi (Tweetphoto) using Oauth? - iphone

I am creating an iphone application in which I have to upload photos using different services.
I am successful in uploading photos with Twitpic & YFrog but not able to do with Plixi.
I am using Oauth ,as Twitter is not allowing Basic authentication.
If anyone has tried with Plixi ,please help me out!!
I have googled a lot but not getting any relevant documentation for the new Oauth for Plixi.

Finally, I am with a solution for my problem :)
If anyone is also stuck with this problem, just add the TweetPhoto folder from the following application link:
http://code.google.com/p/tweetphoto-api-objective-c/downloads/detail?name=TPAPI-Objective-C-Library.zip
Change the tweetphoto urls for plixi now.
Also, can refer to my following code for making function calls:
-(void)uploadtoTweetPhoto{
NSString *message = [self.tweetTextView.text stringByReplacingOccurrencesOfString:#"Max. 140 characters" withString:#""];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
if((message == nil) || ([message isEqual:#""])){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Please enter your tweet message.." message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
else{
[dictionary setObject:message forKey:#"message"];
}
if([dictionary count] == 1){
[indicator startAnimating];
[NSThread detachNewThreadSelector:#selector(uploadPhotoToTweetPhoto:) toTarget:self withObject:dictionary];
}
[dictionary release];
}
- (void)uploadPhotoToTweetPhoto:(NSDictionary *)dictionary{
NSString *message = [dictionary objectForKey:#"message"];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *accessTokenKey = [[NSUserDefaults standardUserDefaults] valueForKey:#"oauth_token"];
NSString *accessTokenSecret = [[NSUserDefaults standardUserDefaults] valueForKey:#"oauth_token_secret"];
TweetPhoto *tweetPhoto = [[TweetPhoto alloc] initWithSetup:accessTokenKey identitySecret:accessTokenSecret apiKey:Plixi_API_Key serviceName:#"Twitter" isoAuth:YES];
NSData *dat =[tweetPhoto upload:UIImageJPEGRepresentation(self.imgView.image,0.8) comment:message tags:#"" latitude:23.4646 longitude:-87.7809 returnType:TweetPhotoCommentReturnTypeXML];
NSString *status =[NSString stringWithFormat:#"%i",[tweetPhoto statusCode]];
[tweetPhoto release];
[self performSelectorOnMainThread:#selector(photoUploadedtoTweetPhoto:) withObject:status waitUntilDone:[NSThread isMainThread]];
[pool release];
}
- (void)photoUploadedtoTweetPhoto:(NSString*)status{
[indicator stopAnimating];
if([status isEqualToString:#"201"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Tweet Posted" message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Tweet Failed" message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
}

I'm curious as to the phrase you used in Google. In any case, googling "plixi api" tool me to this page, which links to a Cocoa wrapper on Google Code.

Related

Warning: Attempt to present <SLTwitterComposeViewController: 0x233141c0> on <MainController: 0x2083ebb0> whose view is not in the window hierarchy

I am receiving this error when trying to post an image to Twitter using the following code, cannot think what I am doing wrong any ideas for how to solve?;
- (void)PostToTwitter
{
UIImage* pxImage = [[self GetResultImage] retain];
TWTweetComposeViewController *twitter = [[[TWTweetComposeViewController alloc] init] autorelease];
[twitter setInitialText:#"Twitter Pic"];
[twitter addImage:pxImage];
FaceAppDelegate* app = (FaceAppDelegate*)[[UIApplication sharedApplication] delegate];
[app.mainCtrl presentViewController:twitter animated:YES completion:NULL];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res)
{
if(res == TWTweetComposeViewControllerResultDone)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Success" message:#"You have posted successfully." delegate:self cancelButtonTitle:#"Close" otherButtonTitles: nil];
[alert show];
[alert release];
}
else if(res == TWTweetComposeViewControllerResultCancelled)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Cancelled" message:#"You have cancelled posting to Twitter." delegate:NULL cancelButtonTitle:#"Close" otherButtonTitles: nil];
[alert show];
[alert release];
}
[app.mainCtrl dismissModalViewControllerAnimated:YES];
};
[pxImage release];
}
I think, that your view isn't presented. Try to use app.window.rootViewController, not property mainContr.

Alert with instructions before gameplay starts

How can I add an alert that displays instructions before game starts:
See code below:
- (void)viewDidLoad
{
[super viewDidLoad];
if (questions && configDictionary) {
[questionLabel setText:[[questions objectAtIndex:currentQuestonIndex] objectForKey:#"question"]];
NSArray *answers = [[questions objectAtIndex:currentQuestonIndex] objectForKey:#"answers"];
[answerLabel0 setText:[answers objectAtIndex:0]];
[answerLabel1 setText:[answers objectAtIndex:1]];
[answerLabel2 setText:[answers objectAtIndex:2]];
[answerLabel3 setText:[answers objectAtIndex:3]];
[pointsPerAnswerLabel setText:[NSString stringWithFormat:#"+%d points", [[configDictionary objectForKey:kPointsPerCorrectAnswer] intValue]]];
[currentQuestionNumberLabel setText:[NSString stringWithFormat:#"question %d", currentQuestonIndex+1]];
}
}
Use a UIAlertView:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Instructions"
message:#"Your Instructions..." delegate:self cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil, nil];
[alert show];
If you want to alert the user every time the app launches place it in the
- (void)applicationDidFinishLaunching:(UIApplication *)application {
}
Edit
You said you wanted to start the game after the dismiss button is pressed. So take advantage of the UIAlertView delegate:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0){
//Start your game!
}
}
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"How to play"
message:#"Answer the questions correctly to get points blablabla..."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];

iPhone iOS 5 SDK in app SMS error

thanks in advance every time I call to create an in app SMS i get the following error...
Application tried to push a nil view controller on target .
This is the code I have that worked in OS 4 SDK...
MFMailComposeViewController *MailController;
MFMessageComposeViewController *SMScontroller;
NSError *error;
NSString *EmailMessage;
NSString *SubjectMessage;
-(IBAction)sendInAppSMS
{
if([MFMessageComposeViewController canSendText])
{
SMScontroller = [[MFMessageComposeViewController alloc] init];
SMScontroller.messageComposeDelegate = self;
NSString *MessageString = #"Hello";
SMScontroller.body = MessageString;
SMScontroller.navigationBar.tintColor = [UIColor blackColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[self presentModalViewController:SMScontroller animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}
else{
// alertView to tell user to setup a mail account.
NSString *message = [[NSString alloc] initWithFormat:#"To use this feature, you need to have an iPhone with SMS abilities."];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"SMS Account Not Detected" message:message delegate:nil cancelButtonTitle:#"Understood" otherButtonTitles:nil];
[alert show];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"I Like It" message:#"User cancelled sending the SMS"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
break;
case MessageComposeResultFailed:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"I Like It" message:#"Error occured while sending the SMS"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
break;
case MessageComposeResultSent:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"I Like It" message:#"SMS sent successfully..!"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
I believe if you are running this in the simulator you'll get the error since it doesn't have sms. I get the same error in simulator but if i connect to my phone it works fine.

memory problem with array releasing in objective-c

i am getting problem with this can any one help me
here is my code. This code work 1st click but when click 2 time it get error
malloc: error for object 0x4e226a4: incorrect checksum for freed object - object was probably modified after being freed.
** set a breakpoint in malloc_error_break to de**bug
- (void)updateTextViewContents {
content = [[NSMutableString alloc] init];
for (int i = 0; i <[ _scoresArray count]; i++)
{
NSMutableString *data = [_scoresArray objectAtIndex:i];
[content appendString:data];
if([content isEqualToString:UserText.text]&&[content isEqualToString:PassText.text])
{
UIAlertView *alt = [[UIAlertView alloc] initWithTitle:nil message:#"Valid User" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alt show];
[alt release];
[content release];
}
else
{
UIAlertView *alt1 = [[UIAlertView alloc] initWithTitle:nil message:#"NOT A Valid User" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alt1 show];
[alt1 release];
}
}
when i release over here it work but when i click 2nd time by entering right user name and password both alter view display at time .I think it will happen because of array get add at every cilck that's why both alter view dispaly at time how i sovle this .
//[content release];
}
Here generate memory problem because of,
you release content NSMutableString in if condition and then append it again.
So, Don't release in to for loop, release it out of for loop.
- (void)updateTextViewContents
{
content = [[NSMutableString alloc] init];
for (int i = 0; i <[ _scoresArray count]; i++)
{
NSMutableString *data = [_scoresArray objectAtIndex:i];
[content appendString:data];
if([content isEqualToString:UserText.text]&&[content isEqualToString:PassText.text])
{
UIAlertView *alt = [[UIAlertView alloc] initWithTitle:nil message:#"Valid User" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alt show];
[alt release];
//[content release]; - Not release here.
}
else
{
UIAlertView *alt1 = [[UIAlertView alloc] initWithTitle:nil message:#"NOT A Valid User" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alt1 show];
[alt1 release];
}
}
[content release];
Can't you replace
NSMutableString *data = [_scoresArray objectAtIndex:i];
[content appendString:data];
with this
[content appendString:[_scoresArray objectAtIndex:i]];
your both alert is showing because of your loop put break after it is valid user because you must not go through loop after it is valid user
hope this will help
good luck
You have release content in the if condition. For the next iteration you are again trying to append data to content, which is already released if the condition was true in previous iteration. And thus you are getting that error object was probably modified after being freed.

iPhone Development xcode : Putting user input (names) into text array

I am trying to load names in an array using UIAlert and then print them one by one. I am not able to figure this out, can anyone help me out with this? I would really appreciate your help.
NSArray *array = [NSArray arrayWithObjects:#"One", #"Two", #"Three", #"Four", nil];
for (NSString *element in array)
{
// Log to console..
NSLog(#"element: %#", element);
//Show in alert.. Really??
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ALERT TITLE" message:element delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
NSArray *array = [NSArray arrayWithObjects:#"One",#"Two",#"Three",nil];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"ALERT TITLE" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
for(NSInteger index=0; index<[array count]; index++)
{
[alert addButtonWithTitle:[array objectAtIndex:index]];
}