The page I want to open using twitter app:
我想用twitter app打开的页面:
https://twitter.com/#!/PAGE
To open twitter app I use the following code:
要打开Twitter应用程序,我使用以下代码:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter://https://twitter.com/#!/PAGE"]];
[[UIApplication sharedApplication] openURL:urlApp];
But this code doesn't seem to work as expected, I got only twitter app launched without the page which i want to show.
但是这段代码似乎没有按预期工作,我只推出了没有我要显示的页面的推特应用程序。
5 个解决方案
#1
39
You are looking for the following url:
您正在寻找以下网址:
twitter:///user?screen_name=PAGE
Note that Twitter is not installed on all devices. You should check the result of openURL
method. If it fails, open the page in Safari with regular url.
请注意,并未在所有设备上安装Twitter。你应该检查openURL方法的结果。如果失败,请使用常规网址在Safari中打开该页面。
#2
14
I know its quite a late response to this question and I agree that, Murat's answer is absolutely correct. Simply add a check as follows:
我知道对这个问题的反应非常晚,我同意,穆拉特的答案是绝对正确的。只需添加一个支票如下:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter:///user?screen_name=PAGE]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}
I hope this helps someone. Cheers!! :)
我希望这可以帮助别人。干杯!! :)
#3
11
The following code opens twitter page on twitter app if it is already installed, otherwise opens twitter on safari:
以下代码在twitter app上打开twitter页面(如果已安装),否则在safari上打开twitter:
NSURL *twitterURL = [NSURL URLWithString:@"twitter://user?screen_name=username"];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];
else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/username"]];
Don't forget to replace 'username' with your name.
不要忘记用您的名字替换'username'。
#4
2
@Alexey: If you just want to know how to launch twitter from your application do this:
@Alexey:如果您只想知道如何从您的应用程序启动Twitter,请执行以下操作:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter://"]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}else{
UIAlertView *appMissingAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter App Not Installed!" message:@"Please install the Twitter App on your iPhone." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[appMissingAlertView show];
[appMissingAlertView release];
}
#5
1
This is the full code required in Swift. I am using Swift 4 but i believe it is the same for Swift 3.
这是Swift所需的完整代码。我使用的是Swift 4,但我相信Swift 3也是如此。
let Username = "YOUR_USERNAME_HERE"
let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")!
let webURL = NSURL(string: "https://twitter.com/\(Username)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
// if Instagram app is not installed, open URL inside Safari
application.open(webURL as URL)
}
Don't forget to add the Info keys needed to use canOpenURL
:
不要忘记添加使用canOpenURL所需的Info键:
#1
39
You are looking for the following url:
您正在寻找以下网址:
twitter:///user?screen_name=PAGE
Note that Twitter is not installed on all devices. You should check the result of openURL
method. If it fails, open the page in Safari with regular url.
请注意,并未在所有设备上安装Twitter。你应该检查openURL方法的结果。如果失败,请使用常规网址在Safari中打开该页面。
#2
14
I know its quite a late response to this question and I agree that, Murat's answer is absolutely correct. Simply add a check as follows:
我知道对这个问题的反应非常晚,我同意,穆拉特的答案是绝对正确的。只需添加一个支票如下:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter:///user?screen_name=PAGE]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}
I hope this helps someone. Cheers!! :)
我希望这可以帮助别人。干杯!! :)
#3
11
The following code opens twitter page on twitter app if it is already installed, otherwise opens twitter on safari:
以下代码在twitter app上打开twitter页面(如果已安装),否则在safari上打开twitter:
NSURL *twitterURL = [NSURL URLWithString:@"twitter://user?screen_name=username"];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];
else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/username"]];
Don't forget to replace 'username' with your name.
不要忘记用您的名字替换'username'。
#4
2
@Alexey: If you just want to know how to launch twitter from your application do this:
@Alexey:如果您只想知道如何从您的应用程序启动Twitter,请执行以下操作:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter://"]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}else{
UIAlertView *appMissingAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter App Not Installed!" message:@"Please install the Twitter App on your iPhone." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[appMissingAlertView show];
[appMissingAlertView release];
}
#5
1
This is the full code required in Swift. I am using Swift 4 but i believe it is the same for Swift 3.
这是Swift所需的完整代码。我使用的是Swift 4,但我相信Swift 3也是如此。
let Username = "YOUR_USERNAME_HERE"
let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")!
let webURL = NSURL(string: "https://twitter.com/\(Username)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
// if Instagram app is not installed, open URL inside Safari
application.open(webURL as URL)
}
Don't forget to add the Info keys needed to use canOpenURL
:
不要忘记添加使用canOpenURL所需的Info键: