在Twitter上与预览iOS共享链接?

时间:2015-09-12 06:56:43

标签: ios ios8 uiactivityviewcontroller

我有一个应用程序,我正在使用Uiactivityviewcontroller.its共享一个链接到Twitter,只是在我的TL中显示文本和Twitter中的链接。我希望它像在Facebook中一样显示从链接中提取的图像。我这样做

    NSURL *shareUrl = [NSURL URLWithString:@“http://dhdhdh”];
  NSString* someText = @“fdfdfd”;

  UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
                                                 initWithText:@"http://dhdhdh"];

  NSArray* dataToShare = @[someText,shareUrl,printData];  // ...or whatever pieces of data you want to share.
  NSArray *appActivities = [NSArray arrayWithObjects:[[UrlActivity alloc] init], nil];
  UIActivityViewController* activityViewController =
        [[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                          applicationActivities:appActivities];
          activityViewController.excludedActivityTypes=@[UIActivityTypeAddToReadingList,UIActivityTypeAirDrop,UIActivityTypePrint,UIActivityTypeAssignToContact];
        // activityViewController.


        [self.navigationController presentViewController:activityViewController animated:YES completion:nil];

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

试试这个

转到目标中的构建设置 - >链接二进制文件库 - >添加“社交”框架

导入#import <Social/Social.h>

NSURL *url = [NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/en/3/38/Avatarjakeneytiri.jpg"];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [controller setInitialText:@"myShare"];
    [controller addImage:img];
    [self presentViewController:controller animated:YES completion:nil];
}
else {
    //wont work in simulator
}