Skip to content

Instantly share code, notes, and snippets.

@jontelang
Created July 18, 2014 11:49
Show Gist options
  • Select an option

  • Save jontelang/c0047d9fcbb2ece2956e to your computer and use it in GitHub Desktop.

Select an option

Save jontelang/c0047d9fcbb2ece2956e to your computer and use it in GitHub Desktop.

Revisions

  1. jontelang created this gist Jul 18, 2014.
    50 changes: 50 additions & 0 deletions asd.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    -(void)presentFBShare{
    // Create an object
    id<FBGraphObject> object =
    [FBGraphObject openGraphObjectForPostWithType:@"thebumapp:share"
    title:@"a bum"
    image:Nil
    url:@"http://www.facebook.com/TheBumApp"
    description:Nil];

    // Create an action
    id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];

    // Link the object to the action
    [action setObject:object forKey:@"bum"];

    /// Package the image inside a dictionary
    NSArray* image = @[@{@"url": self.imageView.image, @"user_generated": @"true"}];
    [action setImage:image];

    // Check if the Facebook app is installed and we can present the share dialog
    FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
    params.action = action;
    params.actionType = @"thebumapp:share";


    // If the Facebook app is installed and we can present the share dialog
    if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
    // Show the share dialog
    [FBDialogs presentShareDialogWithOpenGraphAction:action
    actionType:@"thebumapp:share"
    previewPropertyName:@"bum"
    handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
    if(error) {
    // There was an error
    LOG([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
    [self showFail];
    } else {
    // Success
    LOG(@"results %@",results);
    if(![results[@"completionGesture"] isEqual:@"cancel"]){
    [self showSuccess];
    }
    }
    }];

    // If the Facebook app is NOT installed and we can't present the share dialog
    } else {
    [self showPleaseInstallFacebookApp];
    }
    }