2

i have used Twitter framework to send tweet.I want to pass some data from application to tweeter but it can't.

My code. `

        if ([TWTweetComposeViewController canSendTweet]) {

        // Initialize Tweet Compose View Controller
        TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
        UITextField *txtFild1=[[UITextField alloc]init];
        txtFild1.text=shareString;
        // Settin The Initial Text
        [vc setInitialText:self.shareString];
        [txtFild1 release];
        // Adding an Image

        // Adding a URL

        // Setting a Completing Handler
        [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [self dismissModalViewControllerAnimated:YES];
        }];

        // Display Tweet Compose View Controller Modally
        [self presentViewController:vc animated:YES completion:nil];

`

my data is in share string. but it don't set as initial text.

How can it solve?

jinal
  • 69
  • 7

1 Answers1

2

First add Twitter.framework from Build Phases => LinkBinary with Libraries and then import this file in your .m file like bellow...

#import <Twitter/TWTweetComposeViewController.h>

and then use this like bellow.. This is just an example..

- (IBAction)CallTwitter
{   
    TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

    [twitter setInitialText:@"Write Some Text Here"];


    [self presentViewController:twitter animated:YES completion:nil];

    twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {

        if(res == TWTweetComposeViewControllerResultDone)
        {

            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your Tweet was posted succesfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];
            [alertView release];



        }else if(res == TWTweetComposeViewControllerResultCancelled)
        {

            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Canceled" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];
            [alertView release];
        }
        [self dismissModalViewControllerAnimated:YES];
    };
}
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • First NSLog this(means print that string) string .. see this isnot nil or empty.. check now.. – Paras Joshi Jan 07 '13 at 12:42
  • @jinal use this line [twitter setInitialText:self.shareString]; – Paras Joshi Jan 07 '13 at 12:44
  • which string(text,data) you want to display on initial text?? – Paras Joshi Jan 07 '13 at 13:01
  • but which type of dynamic data you want to display?? means if here string is @"" then some other data is display like if string is @"" the text display 'Title' text right?? – Paras Joshi Jan 07 '13 at 13:12
  • if i write in setIntial text like this @"Hello!!" then it dissplay in twitter box of iphone.But i have data in sharestring from table view so i directly pass that string.But data of that string is not shown in twitter box.and sharestring have data. – jinal Jan 07 '13 at 13:33
  • are you sure you have a data?? in sharestring?? just properly just property-syantesize that string and retain it and then use it i am sure it will work.. i give another answer to someone before a minute for property-synthesize the string from this link see http://stackoverflow.com/questions/14196708/change-a-uilabels-text-from-another-class/14196872#14196708 – Paras Joshi Jan 07 '13 at 13:35
  • @property(nonatomic,retain)NSString *shareString; and when i have write NSLog(@"%@",self.sharestring).i get data @"This business directory is shared to you via....".in TWTwittercomposer code given by you. – jinal Jan 07 '13 at 13:39
  • http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/ i try to link twitter another way in my app.But tweet not post in twitter. – jinal Jan 07 '13 at 13:43
  • here its limited string allowed to tweet on tweeter but here you get the output from this code??? – Paras Joshi Jan 08 '13 at 04:39
  • if i write like this [twitter setInitialText:@"Write Some Text Here"]; then it show but when write [twitter setInitialText:self.sharestring];then no data display of sharestring. – jinal Jan 08 '13 at 05:17
  • i know why its happen , bcoz here character limit of Initial text is 140, if you want to set text then here you must enter < 140 character.. – Paras Joshi Jan 08 '13 at 05:20
  • @jinal see this link for more information about it... http://en.wikipedia.org/wiki/Twitter – Paras Joshi Jan 08 '13 at 05:22
  • @jinal you got it now?? whats the problem here.. just substring your string with only 135 character and set as a initialText.. – Paras Joshi Jan 08 '13 at 05:36
  • always wel-come dear.. also you can just take 135 character from string and post it on it with substringFromIndex method of NSString.. and if this answer helpful then accept the answer and also another answer from this http://stackoverflow.com/questions/14196708/change-a-uilabels-text-from-another-class/14196872#14196708 link of your que.. increase your rate dear.. Thank you... :) – Paras Joshi Jan 08 '13 at 05:40
  • @jinal oh sorry dear on this link i give you answer its helpful ?? http://stackoverflow.com/questions/14136786/cant-dial-call-from-programatically-in-iphone if helpful then also accept that answer dear.. – Paras Joshi Jan 08 '13 at 05:44
  • i want to use facebook from iphone by default like twitter.But this available only in ios6.0.If want to use in ios5.0 then? – jinal Jan 08 '13 at 05:56
  • now you got it?? see the answer http://stackoverflow.com/questions/12735962/supporting-both-ios-5-and-ios-6-with-the-facebook-sdk-3-1 .. now you got it?? – Paras Joshi Jan 08 '13 at 06:54
  • http://stackoverflow.com/questions/14252311/facebook-integration-in-iphone-with-facebook-sdk-for-ios5-and-6/14252595#14252595 can you give answer for this? – jinal Jan 10 '13 at 12:00
  • then that not work but for that use sharekit or any other sdk for facebook just see my this answer for some sdk of facebook but use sharkit for that just take links from comment also http://stackoverflow.com/questions/14214903/facebook-sdk-changes-to-login-in-pop-up-view/14215393#comment19817219_14215393 – Paras Joshi Jan 11 '13 at 09:07
  • http://stackoverflow.com/questions/14376759/apply-bezier-path-to-image-instead-of-imageview can you give answer of it? – jinal Jan 17 '13 at 11:54