55

A tweet can be opened by Safari with a link of this format:

http://twitter.com/1Direction_X/statuses/197752514391715842

On iOS 5, Twitter is built-in. How can I open the above tweet using the native Twitter app called from my app?

158

This is how you access other apps from your own. Just find the proper url to send for accessing status. I've included a list that should have most of the important ones. Including status finding.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://status?id=12345"]];

twitter://user?screen_name=lorenb

twitter://user?id=12345

twitter://status?id=12345

twitter://timeline

twitter://mentions

twitter://messages

twitter://list?screen_name=lorenb&slug=abcd

twitter://post?message=hello%20world

twitter://post?message=hello%20world&in_reply_to_status_id=12345

twitter://search?query=%23hashtag

Note: It can be important to make sure the user has twitter installed or this will cause a crash. So I recommend adding this in an if statement before you try to send them to twitter.

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];
  • 1
    Any idea how you can search for a hash tag?? I've tried NSURL *twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter://search?q=%@", hashTag]]; but no luck... – Smikey Jun 11 '12 at 14:01
  • I don't know sorry. You may not be able to. THis isn't the entire Twitter API just a URLScheme for the app. They may not have built that function in. – Ryan Poolos Jun 11 '12 at 15:58
  • 2
    If the check fails (user does not have Twitter installed) I would fall back to launching the corresponding profile/etc. on Safari – Nicolas Miari Jun 12 '12 at 7:03
  • 2
    On binpress I have a Twitter Smart Link that if Twitter fails will open up the link in a UIWebView Modal within the app. binpress.com/app/in-app-twitter-smart-link/204 – Ryan Poolos Jun 12 '12 at 12:08
  • 1
    Nice one @Hafthor I'll add it to the post incase someone else comes along. – Ryan Poolos Dec 12 '12 at 17:51
-1

My apologies if this has already been answered, but the schema for posting a message with a hashtag is:

twitter://post?message=hello%20world%23thisisyourhashtag.  

Just replace thisisyourhashtag with the hashtag that you would like users to post.

  • This isn't actually a schema specific to hashtags. Any message to be sent should be encoded before using it in a URL. During the encoding, any hash signs will become %23. – L S Jul 8 '17 at 11:41
2

I would go with below approach...

NSURL *twitterURL = [NSURL URLWithString:@"fb://profile/<profile_id>"];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
    [[UIApplication sharedApplication] openURL:twitterURL];
} else {
    WebViewViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"webinterface"];

    secondView.headerLabel = @"Facebook";
    secondView.webPath = @"https://www.facebook.com/pages/<link_for_page>";

    [self.navigationController pushViewController:secondView animated:YES];
}

in WebViewViewController I have webview and I am opening link there...

basically its like if you don't have Twitter on iPhone, it will open in WebView...

  • 5
    Are you sure this is for opening Twitter..? ;) – moffeltje Mar 1 '16 at 12:50
  • @moffeltje : Thanks for catching this... Atlast after 2.5 years... ;) – Fahim Parkar Mar 1 '16 at 13:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.