[Bug][TwitterKit][iOS] TwitterKit fails to tweet if Twitter app is installed on device



I am adding a feature to an existing iOS app which should allow the user to share an achievement via Twitter. The app has been installed onto two test devices, both signed into a Twitter account in Settings. The feature has the latest TwitterKit library (2.3.0) installed from Cocoapods; it also uses Crashlytics.

When the app tries to create a tweet, it tries to log in to Twitter, to create a TWTRSession. If successful, it creates and populates a TWTRComposer and displays it to the user. The user is able to edit the text and press post. The composer’s completion handler reports that the tweet was not cancelled, and logs out to end the session.

On the device which does not have Twitter installed, the tweet is successfully posted to the user’s timeline (checked on a different machine, naturally).
On the device which does have Twitter installed, the tweet is not posted. If the Twitter app is opened to check on the status of the tweet, an alert view is displayed, stating that there has been an error, and that the tweet has instead been saved to the Drafts folder.

Clearly there are other apps out there which are able to share tweets successfully even if the Twitter app is installed. However, I don’t know what steps I might have missed for my app. The TwitterKit documentation covers a lot of functionality, such as tweeting cards, viewing the user’s timeline, reading tweets etc., but does not make clear which installation steps or authorisation procedures are prerequisites for which functions, so I can’t tell which steps are necessary and which are irrelevant. During my search for a solution, I’ve found several stack overflow posts describing the same problem, but no-one has responded to them.

What should I do next?


Hey @narrativium,

It sounds like something very funky is happening and I’d love to dig into this more. Can you send over the Console output after a successful tweet and some of the code around this?



@bonnell: thanks for your reply. It does seem very strange.

Here’s the Objective C code:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
	if (session)
		NSLog(@"signed in as %@", [session userName]);

		TWTRComposer *composer = [[TWTRComposer alloc] init];

		[composer setText: text]];
		[composer setImage: image];
		[composer setURL: url ];

		// Called from a UIViewController
		[composer showFromViewController:self completion:^(TWTRComposerResult result) {
			if (result == TWTRComposerResultCancelled) {
				NSLog(@"Tweet composition cancelled");
				[[Twitter sharedInstance].sessionStore logOutUserID:[session userID]];
			else {
				NSLog(@"Sending Tweet!");
				[[Twitter sharedInstance].sessionStore logOutUserID:[session userID]];
		NSLog(@"error: %@", [error localizedDescription]);
		UIAlertController *noTwitterAlertController = [UIAlertController alertControllerWithTitle:@"Please connect your device to Twitter" message:@"Your device isn't associated with a Twitter account. Please connect to an account in your device settings." preferredStyle:UIAlertControllerStyleAlert];
		[self presentViewController:noTwitterAlertController animated:YES completion:nil];

Here’s the console output:

2016-07-15 10:42:24.756 <AppName>[3201:1707748] signed in as <username>
2016-07-15 10:42:27.753 <AppName>[3201:1707748] Sending Tweet!
2016-07-15 10:56:03.853 <AppName>[3201:1710505] plugin com.apple.share.Twitter.post invalidated

Once this displays the TWTRComposer’s view disappears and the user can continue using the app.

On the device with the Twitter app installed, the tweet is not posted. When the Twitter app launches, it displays an UIAlertView (or UIAlertController styled to Alert) with this title: “Tweet failed to send”, message: “Your Tweet couldn’t be sent and has been saved as a draft.”, options: “Drafts”, “OK”.

What else I can think of that might be relevant so far:
I’m using Xcode 7.3.
The app’s been developed and maintained in Objective C, but if there’s a Swift solution I can use that too.
The app has been developed to support iOS 7, for which Cocoapods has installed TwitterKit 1.15.3. I’ve tried increasing the minimum deployment target to iOS 8.0, so that Cocoapods can install the latest TwitterKit, 2.3.0. This has made no difference to the experienced problem.
The device which successfully tweets is an iPod Touch running iOS 8.4. The device which has Twitter installed and fails is an iPad mini 2 running the latest iOS 9.3.

In the project:
<TwitterKit/TwitterKit.h> is imported in the .m file with the above code.
[Fabric with:@[[Crashlytics class], [Twitter class]]]; is called in the AppDelegate’s application:didFinishLaunchingWithOptions: method.
Both Crashlytics and Twitter have been added to the app’s Info.plist, as dictionaries in the Fabric/Kits array. The dictionary whose KitName is ‘Twitter’ has a KitInfo dictionary containing the app’s consumerKey and consumerSecret.

Any suggestions?


I don’t know whether forum etiquette here allows me to bump this, so apologies if I’m breaching a rule.

@bonnell : have you had chance to dig into this?

Anyone else: any suggestions on any app configuration steps I might have missed in the process of allowing the user to share an achievement via tweet?


Thanks for the bump @narrativium - totally appropriate in this case :slight_smile: It had dropped off my radar to dig into, will look soon. Sorry!


I also have this issue!! any update??


Thanks @rod5438, I haven’t been able to reproduce this yet - is your code and setup similar to @narrativium’s?


SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[vc addImage:image];
[vc setInitialText:@“some text”];
[self presentViewController:vc animated:YES completion:nil];

And only happens if using iPad.
My iPhone is OK.