Cannot compose tweets with Twitter Kit 3

这一生的挚爱 提交于 2019-12-08 05:20:35

问题


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

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?


回答1:


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 key checking your exist only read permissions users, I mean using this key is an optional.



来源:https://stackoverflow.com/questions/46094360/cannot-compose-tweets-with-twitter-kit-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!