通过UIActivityViewController在Facebook / Twitter上共享图像已停止在iOS 8中工作

时间:2014-10-01 10:58:01

标签: facebook twitter ios8 sharing uiactivityviewcontroller

我在iOS 7的FB / Twitter中拥有完美的图像共享代码。

- (NSArray *)activityViewController:(NSArray *)activityViewController itemsForActivityType:(NSString *)activityType
{
...
  if ([activityType isEqualToString:UIActivityTypePostToFacebook] ||
      [activityType isEqualToString:UIActivityTypePostToTwitter])
    return @[@"text", [UIImage imageNamed:@"myImage"]];
...
}

更新到iOS 8后,我只是在发布窗口中看到空白图片,并且没有任何内容发布到社交网络。

想法?

1 个答案:

答案 0 :(得分:0)

以下是我为视频分享所做的工作。您可以尝试相同的图像。

我首先将视频数据保存到文档目录中的文件中,然后附加了该文件。

//write to a file [videoData writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.mov"] atomically:YES];

然后

- (IBAction)ShareVideoWihFacebook:(id)sender {
    //get the file url NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.mov"];

    NSURL *videoURL = [NSURL fileURLWithPath:path];
    UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[videoURL,@"Created by ..."] applicationActivities:NULL];

    [activityVC setExcludedActivityTypes:@[ UIActivityTypeMail,UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint, UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll]];
    [activityVC setValue:@"My Video" forKey:@"subject"];

    [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
        //NSLog(@"completed dialog - activity: %@ - finished flag: %d", activityType, completed);
    }];

    [self presentViewController:activityVC animated:TRUE completion:nil];
}