如何在 iOS 上使用本机 Twitter 应用程序打开 Twitter 推文?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10424275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:13:53  来源:igfitidea点击:

How can I open a Twitter tweet using the native Twitter app on iOS?

iphoneiosxcodetwitter

提问by vietstone

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

Safari 可以使用以下格式的链接打开推文:

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?

在 iOS 5 上,Twitter 是内置的。如何使用从我的应用程序调用的本机 Twitter 应用程序打开上述推文?

回答by Ryan Poolos

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.

这是您从自己的应用程序访问其他应用程序的方式。只需找到发送访问状态的正确 url。我已经列出了一个列表,其中应该包含大部分重要内容。包括状态查找。

[[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

twitter://user?screen_name=lorenb

推特://用户?id=12345

推特://status?id=12345

推特://时间线

推特://提及

推特://消息

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.

注意:确保用户安装了 Twitter 可能很重要,否则会导致崩溃。因此,我建议在您尝试将它们发送到 Twitter 之前,将其添加到 if 语句中。

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];

回答by Fahim Parkar

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 WebViewViewControllerI have webview and I am opening link there...

WebViewViewController我有 webview 并且我在那里打开链接...

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

基本上就像如果你在 iPhone 上没有 Twitter,它将在 WebView 中打开......

回答by Dustin B.

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 thisisyourhashtagwith the hashtag that you would like users to post.

只需替换thisisyourhashtag为您希望用户发布的主题标签即可。