在iOS 7.1中使用UIActivityViewController无法在Facebook和Twitter上分享URL

6

我正在使用UIActivityViewController来实现分享按钮。当我从列表中选择邮件选项时,它会显示文本和URL,但是当我选择Facebook或Twitter时,它只显示文本而不显示URL。我搜索了很多但没有找到解决办法。我得到了另一个解决方案,即在URL中添加“http”,但是不添加“http”是否可能?我的代码如下 -

 NSArray *activityItems;
NSString *str;
NSString *noteStr;
str = [NSString stringWithFormat:@"com.boxscoregames.squares://square?%@",squareID];
noteStr = @"You have been invited to join the Square game, please follow the link below on your iPhone.";
NSURL *url = [NSURL URLWithString:str];

// str =[NSString  stringWithFormat:@"<html><a href=\"%@\">%@</a></html>" ,str,str];
activityItems = @[noteStr,url];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
1个回答

6
我认为链接确实没有显示出来。但是,当你发布帖子时,链接将会被添加到你的Facebook/twitter帖子中。
当然,你也可以在文字中直接添加链接。
NSString *link = [NSString stringWithFormat:@"com.boxscoregames.squares://square?%@",squareID];
NSString *noteStr = [NSString stringWithFormat:@"You have been invited to join the Square game, please follow the link below on your iPhone. %@", link];

NSURL *url = [NSURL URLWithString:link];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[noteStr, url] applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

谢谢您的回复。是的,它在手机上运行,并且只有在我检查手机时才显示。 - Chaaruu Jadhav
但是我想将字符串和URL同时作为字符串传递,并在我的应用程序中重定向。 - Chaaruu Jadhav
以上代码将显示“注释”和“链接URL”。它还将在您的帖子中添加链接。 - Maarten
现在我的URL又变了。我的代码是: str = [NSString stringWithFormat:@"sportssquares://square?%@",squareID]; noteStr = @"您已被邀请加入Square游戏,请在您的iPhone上点击下面的链接。"; NSURL *url = [NSURL URLWithString:str]; activityItems = @[noteStr,url];但是它给我一个错误提示:"无法发布到Facebook - 连接到Facebook失败"。 - Chaaruu Jadhav

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接