I am trying to integrate twitter framework into my app to give the users the option
to tweet their calculated results. Tweeting works fine but I’m unable to get the results
to the Twitter window automatically.
- User enters played holes and strokes needed on the golf course.
- App calculates average strokes per hole.
- After clicking on tweet results button twitter window appears and has already
the calculated average as a part of the twitter message.
Right now the Twitter window shows up but I can only assign static text as default.
Can anyone help?
Here is my code:
CALCULATION: (works fine)
- (IBAction)calculateNow:(id)sender {
double holes = [[holesTextField text]doubleValue];
double strokes = [[strokesTextField text]doubleValue];
double result = strokes / holes;
[averageTextField setText:[NSString stringWithFormat:@"%.2f", result]];
}
TWITTER: (works but window does not include the calculated average)
- (IBAction)tweetMyAverage:(id)sender {
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc]init];
[tweetSheet setInitialText:[NSString stringWithFormat:@"My Average is: %@", result]];
[self presentModalViewController:tweetSheet animated:YES];
}
}
I think that the variable result (from the calculation) is not
known in the twitter IBAction but how can I make it available?
Add an variable to your .h file in the
@interfacesection:Then it will be available to use in your .m in every method.
Remove the
doubleclass from the instance variable you create in thecalculateNowmethod to make sure you don’t get a warning as you are creating a separate variable.Also, make sure that you use
%dfor doubles,%@is for strings.