Pla*_*sma 9 twitter facebook objective-c openurl ios
我很确定在发布这个帖子后一小时我可能会找到答案,但我已经找了一个多小时了,似乎无法解决这个问题.所以这里..
我想在我的应用程序中添加一些简单的"联系我们"链接,如果可用的话,可以在其中一个Twitter应用程序中打开我的个人资料...."Twitter","Tweetbot","Twitterriffic"或Facebook回归到如果没有可用的Safari.我不想为twitter等添加完整的API,因为它只是一个联系页面,我不需要访问他们的时间线,或者知道他们的用户ID等.
我在手机上使用的Tweetbot APP和处理程序工作正常(见下文)并打开我的个人资料页面,但我似乎无法获得默认的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"]];
Run Code Online (Sandbox Code Playgroud)
现在我在这里得到了相当多的信息,但我无法让它与Tweetbot和Safari分开.我猜测URL部分格式错误,但我无法找到解释它应该如何的地方.Google搜索会显示包含twitter和facebook标签的页面,但没有有用的信息,而且Twitter API文档对于我想要执行的简单实现来说过于详细.任何人都可以帮助我使用正确的URL格式吗?
[编辑]花了我一个多小时,但这里至少是Twitter的..
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];
Run Code Online (Sandbox Code Playgroud)
还在Facebook上工作!! 尽管我在这里偶然发现了这个问题,但我不能肯定答案
当我将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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2633 次 |
| 最近记录: |