Twitter Kit SDK iOS. Can't tweet from app. Returns to app after "Connect your account" page



I previously used iOS’s built in Social framework and now am trying to migrate my app to Twitter 3. My app is running iOS11 and written in Swift. I have tried following all the instructions online here:

When I run some basic things:

    if (Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
        // App must have at least one logged-in user to compose a Tweet
        let composer = TWTRComposerViewController.emptyComposer()
        present(composer, animated: true, completion: nil)
    } else {
        // Log in, and then check again
        Twitter.sharedInstance().logIn { session, error in
            if session != nil { // Log in succeeded
                let composer = TWTRComposerViewController.emptyComposer()
                self.present(composer, animated: true, completion: nil)
            } else {
                let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
                self.present(alert, animated: false, completion: nil)

even though I am already logged in to my account on the Twitter app, it doesn’t seem to be connecting properly. The “Connect your account” page comes up. When I press the Connect button on this page, it just sends me back to my app. No Tweet composer shows up. If I do it again, same thing. This problem was brought up here as well, but no specific solution was given.

What might cause this? I have made sure that my application on Twitter allows read and write permissions.


Did you set URL Schemes for twitter in your application
and implemented codes to handle login redirect ?

Composing a tweet needs logged in session, and those processes are needed to make your app’s session logged in.


Thanks so much for the reply.

I have this in my plist:









this in my app delegate

func application(_ application: UIApplication, open url: URL,
sourceApplication: String?, annotation: Any, options: [
UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { // added this

if Twitter.sharedInstance().application(application, open: url,

options: options) {

    return true


return IsReportingFBEvents ? FBSDKApplicationDelegate.sharedInstance

().application(application, open: url, sourceApplication:
sourceApplication, annotation: annotation) : true

I’m sure I’m just missing something idiotic – but sooo frustrating :slight_smile:


The original poster of the SO question you referenced does answer his own question with a link to a Japanese language page. The solution there separates authentication into its own function which worked for me.

  • (void)tweetMain
    // Twitter 認証トークンのチェック
    if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) { // 認証トークンあり
    [self tweet];

} else { // 認証トークンなし
// Twitterログイン
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) { // ログイン OK
NSLog(@“signed in as %@”, [session userName]);

[self tweet];

} else { // ログイン キャンセル
NSLog(@“error: %@”, [error localizedDescription]);

  • (void)tweet
    // Twitter投稿データ編集
    TWTRComposer *composer = [[TWTRComposer alloc] init];
    [composer setText:@“hoge”];
    [composer setImage:[UIImage imageNamed:@“twitterkit”]];
    [composer setURL:[NSURL URLWithString:@“”]];

// Twitter投稿画面表示
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) { // キャンセル
NSLog(@“Tweet composition cancelled”);
else {
NSLog(@“Sending Tweet!”);


Probably you forgot to add this code in AppDelegate,

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
     TWTRTwitter.sharedInstance().application(app, open: url, options: options)
     return true