0

I'm looking to add functionality that when an event happens on my app, it will post to my facebook timeline. That said, I'm trying to get it to look very similar to how when you post a youtube video to the timeline where there is a thumbnail image to the left and a title and subtitle next to it.

Anyone have any ideas how I can accomplish this?

Mikerizzo
  • 587
  • 1
  • 4
  • 22

1 Answers1

0

You can't make a post automatically from code, but you can open a system window with predefined message and image attachment.

Sample code:

- (BOOL)postToFacebook:(NSString*)title andDescription:(NSString*)description {
    UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];
    UIViewController *vc = [frontWindow rootViewController];

    BOOL success = NO;
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result) {

            if (result == SLComposeViewControllerResultCancelled) {

            } else {

            }

            [controller dismissViewControllerAnimated:YES completion:Nil];
        };
        controller.completionHandler = myBlock;

        [controller setTitle:title];
        [controller setInitialText:description];
        [controller addURL:[NSURL URLWithString:@"http://example.com"]];
        [controller addImage:[UIImage imageNamed:@"sampleImage.png"]];

        [vc presentViewController:controller animated:YES completion:^{

        }];

        success = YES;
    }
    return success;
}


Remember to add two frameworks:

Social.framework
Accounts.framework

ArturOlszak
  • 2,653
  • 2
  • 21
  • 20