Created
July 18, 2014 11:49
-
-
Save jontelang/c0047d9fcbb2ece2956e to your computer and use it in GitHub Desktop.
asd.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment