Search code examples
iosobjective-ctwitter

Tweetbot URL Scheme not opening user


I've been trying to get Tweetbot to open a user account when a table row is tapped by the user. However, although Tweetbot opens, it doesn't show the user account. I've been using the Tweetbot URL Scheme page as a reference.

Below is my code:

if (indexPath.row == 1) {
        // Removed the actual username
        self.destViewURL = @"http://twitter.com/dummyusername";
        self.destViewTitle = @"Twitter";
        
        // URLs to try
        NSURL *twitterURL = [NSURL URLWithString:@"twitter://user?screen_name= dummyusername"];
        NSURL *tweetbotURL = [NSURL URLWithString:@"tweetbot://dummyusername/timeline"];

        // Check if Tweetbot is available to open it
        if ([[UIApplication sharedApplication] canOpenURL:tweetbotURL]) {
            [[UIApplication sharedApplication] openURL:tweetbotURL];
        }
        
        else {
            // Check if Twitter is available to open it
            if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
                [[UIApplication sharedApplication] openURL:twitterURL];
            }
            
            // Otherwise open it in the web view
            else {
                [self performSegueWithIdentifier:@"showWebView" sender:nil];
            }

Solution

  • The URL schemes page for Tweetbot 3 is here

    All of the supported URLs begin with tweetbot://<screenname>, which suggests that you need to know the user's existing twitter screen name to link to a profile.

    However, my testing has shown that you could link directly to a profile by using the same value for tweetbot://<screenname>/user_profile/<profile_screenname>

    Swift e.g.

       /* Tweetbot app precedence */
       if let tweetbotURL = NSURL(string: "tweetbot://dummyusername/user_profile/dummyusername") {
            if UIApplication.sharedApplication().canOpenURL(tweetbotURL) {
                UIApplication.sharedApplication().openURL(tweetbotURL)
                return
            }
        }
    
        /* Twitter app fallback */
        if let twitterURL = NSURL(string: "twitter:///user?screen_name= dummyusername") {
            if UIApplication.sharedApplication().canOpenURL(twitterURL) {
                UIApplication.sharedApplication().openURL(twitterURL)
                return
            }
        }
    
        /* Safari fallback */
        if let webURL = NSURL(string: "http://www.twitter.com/dummyusername") {
            if UIApplication.sharedApplication().canOpenURL(webURL) {
                UIApplication.sharedApplication().openURL(webURL)
            }
        }