A couple of weeks back I wrote an article about sharing tweets with React Native’s Linking API. Since then I noticed that this method has stopped working on iOS, but I’m not sure if it’s an issue with my iPhone SE or if Twitter has updated their app and changed the URL schemes. It still seems to be working fine on Android(and you can still get the same dialogue on iOS if you use ‘twitter://post‘ instead of ‘https://twitter.com/intent/tweet‘). I tested quite a few different things trying to find a simple and consistent way to tweet on iOS this week and for now I’ve found a pretty simple solution: SLComposeViewController. It isn’t without issues though…

SLComposeViewController and Tweeting

I ended up making a native module in my React Native project and using SLComposeViewController, react-native-social-share seems to do the same thing but I couldn’t get it to compile for some reason. Anyway, composing a tweet with SLComposeViewController is quite straightforward:


When you call this if the user has Twitter installed and is signed in they will see this kind of dialogue:

SLComposeViewController and Tweeting

The tweet dialogue

What are the issues with SLComposeViewController?

Apple seems to be phasing this API out. I’ve also heard things about them de-coupling social accounts from iOS. SLServiceTypeTwitter is actually marked as deprecated since iOS11.0 in Xcode. You can still use it without any issues for now, but apparently there were some problems when iOS 11 was still in beta testing and Twitter had to work around them. Who knows if this approach will still work in iOS 12. TwitterKit has something called TWTRComposer which seems to do something similar but you actually have to create an app in Twitter’s developer dashboard and users need to authorize your app before even being able to tweet…This seems very in-elegant to me for such a simple feature.

SLComposeViewController also seems to have some strange bugs with tweeting in iOS 11. When I tried using the addURL method the text and URL got mushed together and it didn’t seem to be working properly. As a work-around I just added the URL to the text provided to setInitialText, as well as hashtags. Hopefully either Apple or Twitter provides another option before iOS 12 comes out, creating a Twitter Developer app and having the user authorize your app before tweeting seems like over kill to me for apps that aren’t even using Twitter as a login option…

If you can figure out a better solution than this or have something to say feel free to comment below. Last week I wrote another post on using SKStoreReview​Controller with React Native, if you’re interested you can read about it here.