首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基本Facebook / Twitter URL处理程序格式

基本Facebook / Twitter URL处理程序格式
EN

Stack Overflow用户
提问于 2012-05-29 14:42:29
回答 2查看 2.7K关注 0票数 9

我很确定在我发这篇文章一小时后,我可能会找到答案,但我已经找了一个多小时了,似乎找不到答案。所以就这样..。

我想把一些简单的“联系我们”链接到我的应用程序,打开我的个人资料在其中一个推特应用程序,如果有."Twitter“、"Tweetbot”、"Twitterriffic",或者Facebook,如果没有可用的话,就会退回到Safari。我不想为twitter等添加完整的API,因为它只是一个联系人页面,我不需要访问他们的时间线,也不需要知道他们的用户ID等等。

我在手机上使用的Tweetbot应用程序和处理程序工作正常(见下文),打开我的配置文件页,但是我似乎无法获得默认的Facebook或Twitter应用程序的工作,应用程序启动,但没有到我各自的配置文件页面(我显然遗漏了测试代码,但这些代码是调用应用程序的代码).

代码语言:javascript
复制
//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"]];

现在我得到了相当多的信息,这里,但无法让它工作,除了Tweetbot和Safari。我猜URL部分的格式是错误的,但是我找不到任何地方来解释它应该是怎样的。Google搜索提供了带有twitter和facebook标记的页面,但没有提供有用的信息,对于我想要做的简单实现来说,Twitter文档太详细了。有人能帮我找到正确的URL格式吗?

编辑花了我一个多小时,但这里至少是针对Twitter的。

代码语言:javascript
复制
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];

还在做Facebook的工作!我无意中发现了这个答案,但我不能接受它的功劳这里

当我让Facebook的一个也工作的时候,我会在这里发布我的代码和所有的部分,以防它帮助别人!

等离子体

编辑2:好的,这是我的代码(我已经删除了我的网站URL和我的facebook ID,但是你会知道的.它弹出一个UI操作表和联系人我们的选项。希望它对别人有用。

代码语言:javascript
复制
#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://support@mywebsite.co.uk?subject=Important%20Email&body="]];
            return;


        case 3:
            //Visit The Website
            [app openURL:[NSURL URLWithString:@"http://www.mywebsite.co.uk"]];
            return;

        case 4:
            //Cancel
            return;

    } 

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-11 08:31:22

请参阅第一篇文章的编辑2,这是完整的解决方案。

等离子体

票数 0
EN

Stack Overflow用户

发布于 2012-06-14 23:09:15

只是你解决方案的额外步骤,

您应该首先检查应用程序是否存在,然后启动它,否则在safari中打开链接。

代码语言:javascript
复制
NSString *filePath = @"/Applications/TweetBot.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
   // launch app
}
else 
{
   // launch safari instead
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10801404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档