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

时间:2014-12-17 10:19:16

标签: ios objective-c xcode6 uiactivityviewcontroller

我正在使用UIActivityViewController进行分享按钮。当我从列表中选择邮件选项时它显示文本和网址但是当我选择Facebook或Twitter时它只显示文本而不是网址。我搜索了一个很多,但没有得到我的问题的解决方案。我还有一个解决方案来添加" 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 个答案:

答案 0 :(得分: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];