不能用Twitter Kit 3撰写推文

我遵循https://dev.twitter.com/twitterkit/ios/compose-tweets的指令,通过iOS 11的Object 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!"); } }]; 

然而,点击[连接您的帐户]屏幕上的连接button后,它会转回应用程序,而无需撰写鸣叫(Twitter已经login)。 看来showFromViewController没有运行。 任何人都有同样的问题?

首先得到您的应用程序在Twitter上的读/写权限

  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键检查你的存在只读权限的用户,我的意思是使用这个键是可选的。