简体   繁体   中英

How to share a post from my app to twitter iOS

I basically want the user to share something from my app to twitter. I was exploring the different methods possible and found SLComposeViewController but it is deprecated. Support for twitterKit has also been officially stopped by twitter. One possible way to do so seems to be like given in the answers in this post . Is there some other better way to do so? I would prefer if the user stays in the app itself (something similar to sharesheet for fb). Thanks!

You can use twitter-kit-ios .

For posting a tweet sample code from documentation would be following

Objective-c

// Objective-C
TWTRComposer *composer = [[TWTRComposer alloc] init];

[composer setText:@"just setting up my Twitter Kit"];
[composer setImage:[UIImage imageNamed:@"twitterkit"]];

// Called from a UIViewController
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
    if (result == TWTRComposerResultCancelled) {
        NSLog(@"Tweet composition cancelled");
    }
    else {
        NSLog(@"Sending Tweet!");
    }
}];

Swift

// Swift
let composer = TWTRComposer()
    
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
    
// Called from a UIViewController
composer.show(from: self.navigationController!) { (result in
    if (result == .done) {
        print("Successfully composed Tweet")
    } else {
        print("Cancelled composing")
    }
}

Straight from the discontinuing blog post you can use, new api endpoints .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM