10

我需要在我的墙上发布一张照片。图片是在我的 iPad 应用程序中生成的。

4

2 回答 2

24

这是我发现的最简单的方法

- (void) postImageToFB:(UIImage*)image
{
    NSData* imageData = UIImageJPEGRepresentation(image, 90);    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    @"This is my drawing!", @"message",
                                    imageData, @"source",
                                    nil];

    [FBRequestConnection startWithGraphPath:@"me/photos"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                          }];
}

如果您想在朋友的墙上发帖,请更改@"me/photos"@"[friendID]/photos"

然后,请求发布和调用方法的权限

if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound)
{
    // No permissions found in session, ask for it
    [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"]
                                               defaultAudience:FBSessionDefaultAudienceFriends
                                             completionHandler:^(FBSession *session, NSError *error)
     {
         // If permissions granted, publish the story
         if (!error) [self postImageToFB:currentDrawing];
     }];
}
// If permissions present, publish the story
else [self postImageToFB:currentDrawing];

将创建一个“[App Name] Photos”相册(如果不存在)

它对我有用!

于 2012-10-20T03:25:41.327 回答
-1

对于 iOS 4.3 和 UI 看起来像 iOS 6.0,我想你想要这样的东西:IOS sharing framework for twitter, facebook, flicr, tumblr

于 2013-01-23T08:13:02.363 回答