gpt4 book ai didi

objective-c - 基本的 Facebook/Twitter URL 处理程序格式

转载 作者:可可西里 更新时间:2023-11-01 03:00:56 25 4
gpt4 key购买 nike

我很确定在我发布这篇文章后一个小时我可能会找到答案,但我已经找了一个多小时但似乎无法解决。所以这里..

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

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

//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"]];

现在我得到了相当多的信息here ,但我无法让它在 Tweetbot 和 Safari 之外工作。我猜 URL 部分的格式不对,但我找不到任何地方来解释它应该是怎样的。谷歌搜索显示带有 twitter 和 facebook 标签的页面,但没有有用的信息,而且 Twitter API 文档对于我想做的简单实现来说太详细了。任何人都可以帮助我使用正确的 URL 格式吗?


[编辑] 我花了一个多小时,但这里至少是 Twitter ..

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];

还在 Facebook 上工作!!虽然我偶然发现了它,但不能相信答案 here

当我的 Facebook 也能正常工作时,我会在这里发布我的代码,以防它对其他人有帮助!

等 ionic


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

#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;

}

}

最佳答案

您的解决方案只是一些额外的步骤,

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

NSString *filePath = @"/Applications/TweetBot.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
// launch app
}
else
{
// launch safari instead
}

关于objective-c - 基本的 Facebook/Twitter URL 处理程序格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10801404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com