4

I am trying to export a screen shot from my application to Facebook using the iOS6 Facebook function. How can I bring out the options inside the application when the button is pressed?

Below is my current code. I want to take the screenshot and at the same time export to Facebook using iOS6 Facebook function.

- (IBAction)export1:(id)sender{

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
                      atScrollPosition:UITableViewScrollPositionTop
                              animated:YES];
exporting.hidden=YES;

CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        // -renderInContext: renders in the coordinate space of the layer,
        // so we must first apply the layer's geometry to the graphics context
        CGContextSaveGState(context);
        // Center the context around the window's anchor point
        CGContextTranslateCTM(context, [window center].x, [window center].y);
        // Apply the window's transform about the anchor point
        CGContextConcatCTM(context, [window transform]);
        // Offset by the portion of the bounds left of and above the anchor point
        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        // Render the layer hierarchy to the current context
        [[window layer] renderInContext:context];

        // Restore the context
        CGContextRestoreGState(context);
    }
}

// Retrieve the screenshot image
CGRect contentRectToCrop = CGRectMake(0, 70, 740, 740);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil);
Boeckm
  • 3,264
  • 4
  • 36
  • 41
Clarence
  • 1,951
  • 2
  • 34
  • 49

3 Answers3

2

Here is how to post images to Facebook easily using the built in Facebook SDK in iOS6. Happy if this helps you in any ways. Happy coding :)

Community
  • 1
  • 1
Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26
2

The Apple Developer Site Gives a new Social.framework for integrating the Social Experiences like Twitter and Facebook.

Refer here.

Tom Elvin
  • 31
  • 3
1

@Clarence i think you should check out latest Facebook SDK for iOS

it also has some tutorials on how to post images on facebook in iOS 6.

Just download the SDK and you will find sample codes in your Documents folder which include a sample HelloFacebookSample which shows how to post image on facebook in iOS 6.

you just need to pass your image object in this method -

[FBNativeDialogs presentShareDialogModallyFrom:self initialText:nil image:croppedImage url:nil handler:nil];

before using above method you need to properly follow v 3.1 installation instructions here

saadnib
  • 11,145
  • 2
  • 33
  • 54