I am trying to implement the native Share dialog from Facebook in a sample application.
Seem to have some problem in doing so.
Things I have done so far:
- Included the latest Facebook SDK
- Included the AdSupport, Social, Account, Security and libsqlite3.dylib.
- Added the sample code from Facebook.
- Added -lsqlite3.0 -ObjC to Other Linker Flags as well
- Added the app id to the plist
- Added the FBUserSettingsViewResources bundle and FacebookSDKResources.bundle to the project
But I can't seem to share the URL. The share dialog doesn't even appear.
My code looks like this:
Viewcontroller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIButton *buttonShare;
}
- (IBAction)shareButtonClicked:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)shareButtonClicked:(id)sender
{
FBShareDialogParams *params = [[FBShareDialogParams alloc] init];
params.link = [NSURL URLWithString:@"https://developers.facebook.com/ios"];
params.picture = [NSURL URLWithString:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
params.name = @"Facebook SDK for iOS";
params.caption = @"Build great apps";
[FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(@"Error: %@", error.description);
} else {
NSLog(@"Success!");
}
}];
}
@end
Not able to share the URL. Need some guidance on this.
This works for me:
Do you have Facebook App installed on your device? The Share dialog only works if you have the Facebook app installed.
From the Share dialog documentation :
From what I saw, iOS 6 will return
NO
for+ canPresentShareDialogWithParams:
. It only responds to+ canPresentOSIntegratedShareDialogWithSession:
. But I could be wrong here.Anyways, this is how I do it - 1. For sharing links :
2.For OpenGraph calls :
Check out other ways to share on iOS here
Hope this helps.