如何通过iOS Social.framework在fb和twitter上上传多张照片



我在SLComposeViewController中只看到addImage:方法,它拍摄单个图像。

有没有办法将一组图像连接到SLComposeViewController并一次性共享?

您需要直接使用Facebook Connect API:iOS SDK不公开此类功能。

您应该查看Graph Photo API的发布部分,该部分建议使用此URL上传图像(不要忘记要求提供publish_stream凭据):

    POST https://graph.facebook.com/USER_ID/photos
message=[optional description]
source=[the image's data]
place=[optional image's location]
With the iOS Facebook Connect SDK that would give us this call, given you have a Facebook instance called facebook and a UIImage instance called image:
[facebook requestWithMethodName:@"/USER_ID/photos"
                      andParams:[NSDictionary dictionaryWithObjectsAndKeys:
                                 UIImageJPEGRepresentation(image, 0.7), @"source",
                                 @"My puppy is so cute!!!", @"message",
                                 nil]
                  andHttpMethod:@"POST"
                    andDelegate:self];

来源作者:ndfred

苹果文档参考

addMultipartData:withName:type:filename:
Specifies a named multipart POST body for this request.
- (void)addMultipartData:(NSData *)data withName:(NSString *)name type:(NSString*)type filename:(NSString *)filename

参数*数据*由多部分组成的POST正文的数据,例如图像或文本。名称由多部分组成的POST主体的名称。这是特定社会服务所期望的名称。类型多部分POST正文的类型。这是多部分数据的MIME内容类型。文件名要POST的附件的文件名。许多社交服务需要文件名才能接受某些POST请求,例如上传图像或视频。如果您的多部分数据不需要文件名,则传入nil

我使用UIActivityViewController代替SLComposeViewController在Facebook上共享多个图像。也可以在Mail和其他应用程序上共享。用户必须在设备上配置社交帐户。

NSString *message = @"initial Text";
UIImage *imageToShare =imageForShareOnMedia; //[UIImage imageNamed:@"test.jpg"];
NSArray *postItems = @[message, imageToShare,imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
                                            initWithActivityItems:postItems
                                            applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

最新更新