How to open the Twitter App from your own iOS App

- by

Opening the Twitter App is pretty much the same as opening the Facebook App discussed earlier, just the URL scheme is different.

This is how we open Twitter so people can follow the user (me in this case, versluis). If the call is unsuccessful, we’ll try to open the Twitter page in Safari. And if that doesn’t work, we’ll display a log message:

- (IBAction)openTwitter:(id)sender {
    
    // open the Twitter App
    if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=versluis"]]) {
        
        // opening the app didn't work - let's open Safari
        if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/versluis"]]) {
            
            // nothing works - perhaps we're not onlye
            NSLog(@"Nothing works. Punt.");
        }
    }
}

To find out which other apps you can opened, and to figure out what scheme they follow:

To register a Custom URL Scheme in your own app:



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.