I'm pretty sure an hour after I post this I may find the answer but I've been looking for over an hour already and can't seem to work it out. So here goes..
I'd like to put some simple "Contact Us" links in to my app which opens my profile in one of these twitter apps if available .... "Twitter", "Tweetbot", "Twitterriffic", or Facebook falling back to Safari if none are available. I don't wish to add a full API for twitter etc, as its merely a contact page, I have no need to access their time lines, or know their user ID's etc.
The Tweetbot APP and handler which I use on my phone works fine (see below) and opens my Profile Page, however I can't seem to get the default Facebook or Twitter app's work, the applications launch but don't got to my respective profile page (I've obviously left out the testing code but these are the lines which call the applications) ....
//Twitter
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://twitter.com/MyTwitterID"]];
//Tweetbot - WORKS!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tweetbot:///user_profile/MyTwitterID"]];
//Fall Back to Safari - WORKS!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/MyTwitterID"]];
//Facebook
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/MyFbID"]];
Now I got a fair bit of information here , but am unable to get it working apart from for Tweetbot and Safari. I'm guessing the URL part is in the wrong format, but I can't find anywhere that explains how it should be. Google searching brings up pages with twitter and facebook tags but no helpful information, and the Twitter API documentation is far too detailed for the simple implementation I want to do. Can anyone help me with the right URL formats?
[EDIT] Took me more than an hour but here it is for Twitter at least ..
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];
Still working on the Facebook one!! Can't take credit for the answer though I stumbled across it here
When I get the Facebook one working too I'll post my code here with all the bits in case it helps someone else!
Plasma
EDIT 2: Ok here is my code (I've removed my website URL and also my facebook ID's but you'll get the idea .... It pops a UI Action Sheet with the Contact Us options.. Hope its of use to someone else.
#pragma mark - Contact Us Methods
- (IBAction)openContact {
UIActionSheet *popupContact = [[UIActionSheet alloc] initWithTitle:@"Contact Us" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Twitter", @"Facebook", @"Email", @"Visit our website", nil];
popupContact.actionSheetStyle = UIActionSheetStyleDefault;
[popupContact showInView:self.parentViewController.tabBarController.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *twitterUserName = @"MyTwitterName";
//Facebook ID (not the page name) check the FB urls for id=XXXXXXXXXXXXXXXX
NSString *facebookUserID = @"XXXXXXXXXXXXXXX";
UIApplication *app = [UIApplication sharedApplication];
switch(buttonIndex){
case 0: {
//Contact Us By Twitter
//Twitter Default
NSURL *twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter://user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:twitterURL])
{
[app openURL:twitterURL];
return;
}
//Tweetbot
NSURL *tweetbotURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetbot:///user_profile/%@", twitterUserName]];
if ([app canOpenURL:tweetbotURL])
{
[app openURL:tweetbotURL];
return;
}
// Tweetie: http://developer.atebits.com/tweetie-iphone/protocol-reference/
NSURL *tweetieURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetie://user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:tweetieURL])
{
[app openURL:tweetieURL];
return;
}
// Birdfeed: http://birdfeed.tumblr.com/post/172994970/url-scheme
NSURL *birdfeedURL = [NSURL URLWithString:[NSString stringWithFormat:@"x-birdfeed://user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:birdfeedURL])
{
[app openURL:birdfeedURL];
return;
}
// Twittelator: http://www.stone.com/Twittelator/Twittelator_API.html
NSURL *twittelatorURL = [NSURL URLWithString:[NSString stringWithFormat:@"twit:///user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:twittelatorURL])
{
[app openURL:twittelatorURL];
return;
}
// Icebird: http://icebirdapp.com/developerdocumentation/
NSURL *icebirdURL = [NSURL URLWithString:[NSString stringWithFormat:@"icebird://user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:icebirdURL])
{
[app openURL:icebirdURL];
return;
}
// Fluttr: no docs
NSURL *fluttrURL = [NSURL URLWithString:[NSString stringWithFormat:@"fluttr://user/%@", twitterUserName]];
if ([app canOpenURL:fluttrURL])
{
[app openURL:fluttrURL];
return;
}
// SimplyTweet: http://motionobj.com/blog/url-schemes-in-simplytweet-23
NSURL *simplytweetURL = [NSURL URLWithString:[NSString stringWithFormat:@"simplytweet:?link=http://twitter.com/%@", twitterUserName]];
if ([app canOpenURL:simplytweetURL])
{
[app openURL:simplytweetURL];
return;
}
// Tweetings: http://tweetings.net/iphone/scheme.html
NSURL *tweetingsURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetings:///user?screen_name=%@", twitterUserName]];
if ([app canOpenURL:tweetingsURL])
{
[app openURL:tweetingsURL];
return;
}
// Echofon: http://echofon.com/twitter/iphone/guide.html
NSURL *echofonURL = [NSURL URLWithString:[NSString stringWithFormat:@"echofon:///user_timeline?%@", twitterUserName]];
if ([app canOpenURL:echofonURL])
{
[app openURL:echofonURL];
return;
}
// --- Fallback: Mobile Twitter in Safari
NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://mobile.twitter.com/%@", twitterUserName]];
[app openURL:safariURL];
return;
}
case 1: {
//Facebook
NSURL *facebookURL = [NSURL URLWithString:[NSString stringWithFormat:@"fb://profile/%@", facebookUserID]];
if ([app canOpenURL:facebookURL])
{
[app openURL:facebookURL];
return;
}
// --- Fallback: Mobile Facebook in Safari
NSURL *safariURL = [NSURL URLWithString:@"https://touch.facebook.com/MyFBName"];
[app openURL:safariURL];
return;
}
case 2:
//Email
[app openURL:[NSURL URLWithString:@"mailto://[email protected]?subject=Important%20Email&body="]];
return;
case 3:
//Visit The Website
[app openURL:[NSURL URLWithString:@"http://www.mywebsite.co.uk"]];
return;
case 4:
//Cancel
return;
}
}