无法使用Twitter Kit 3撰写推文 [英] Cannot compose tweets with Twitter Kit 3

查看:71
本文介绍了无法使用Twitter Kit 3撰写推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 https://dev.twitter.com/twitterkit/ios的指示进行操作/compose-tweets 通过我的iOS 11 Object C应用撰写推文

I followed instruction from https://dev.twitter.com/twitterkit/ios/compose-tweets to compose tweets via my Object C app for iOS 11

// 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!");
    }
}];

但是,在[连接您的帐户]屏幕上单击连接"按钮后,它关闭了应用程序而没有编写推文(Twitter已登录).似乎showFromViewController没有运行.有人遇到过同样的问题吗?

However, after clicking Connect button at [Connect your account] screen, it turned back app without composing tweet (Twitter logged in already). It seems showFromViewController didn't run. Anyone had the same problem?

推荐答案

首先在Twitter上为您的应用获得读取/写入权限.

First of all get read/write permission on Twitter for your app.

    if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
  NSString *twitterLoggedInInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"TwitterLoggedInInfo"];

  if (![twitterLoggedInInfo isEqualToString:@"v3"]) {
    NSString *currentUserID = [Twitter sharedInstance].sessionStore.session.userID;
    [[Twitter sharedInstance].sessionStore logOutUserID:currentUserID];

    [[NSUserDefaults standardUserDefaults] setObject:@"v3" forKey:@"TwitterLoggedInInfo"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
      if (session) {
        TWTRComposerViewController *composer = [[TWTRComposerViewController alloc] initWithInitialText:tweetText image:tweetImage videoURL:nil];
        [self presentViewController:composer animated:YES completion:nil];
      }
    }];
  } else {
    if (![twitterLoggedInInfo isEqualToString:@"v3"]) {
      [[NSUserDefaults standardUserDefaults] setObject:@"v3" forKey:@"TwitterLoggedInInfo"];
      [[NSUserDefaults standardUserDefaults] synchronize];
    }

    TWTRComposerViewController *composer = [[TWTRComposerViewController alloc] initWithInitialText:tweetText image:tweetImage videoURL:nil];
    [self presentViewController:composer animated:YES completion:nil];
  }
  } else {
    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
      if (session) {
        TWTRComposerViewController *composer = [[TWTRComposerViewController alloc] initWithInitialText:tweetText image:tweetImage videoURL:nil];
        [self presentViewController:composer animated:YES completion:nil];
      }
    }];
  }

TwitterLoggedInInfo 键仅检查您是否存在读取权限个用户,我的意思是,使用此键是可选的.

TwitterLoggedInInfo key checking your exist only read permissions users, I mean using this key is an optional.

这篇关于无法使用Twitter Kit 3撰写推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆