【发布时间】:2012-05-29 14:42:29
【问题描述】:
我敢肯定,在我发布此消息一小时后,我可能会找到答案,但我已经找了一个多小时,但似乎无法解决。就这样吧。。
我想在我的应用程序中添加一些简单的“联系我们”链接,如果可用,该链接会在这些 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 部分的格式有误,但我找不到任何解释它应该如何的地方。 Google 搜索会显示带有 twitter 和 facebook 标签但没有有用信息的页面,而且 Twitter API 文档对于我想要做的简单实现来说太详细了。谁能帮助我正确的 URL 格式?
[编辑] 花了我一个多小时,但至少在这里是 Twitter ..
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];
仍在 Facebook 上工作!!尽管我偶然发现了答案here
当我让 Facebook 也能正常工作时,我会在这里发布我的代码以及所有代码,以防它帮助其他人!
等离子
编辑 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;
}
}
【问题讨论】:
标签: objective-c ios facebook twitter openurl