I'm making a website. On it, I wan开发者_JAVA技巧t to have a link to my twitter account, http://twitter.com/[username].
On iOS devices, I've coded it so that it goes to twitter://[username], the iOS URL scheme for the official Twitter app. However, if the user does not have this app installed, safari just errors, saying that the 'URL is invalid'.
Does anyone know a way around this, so that it'll load the app if they have it, and the normal web URL if they don't?
You can not access anything external to your application, so you will not be able to see if another application has been installed.
One option would be to load your profile in a web view and then at least they can get to your profile.
For anyone who stumbles upon this page and still wants further clarification, you can use an if/else statement.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter:@user"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter:@user"]];
}
else
{
webView.urlString = @"http://www.twitter.com/user";
[[self navigationController] pushViewController:webView animated:YES];
[netView release];
netView = nil;
}
精彩评论