How to Share Link on Facebook using FBSDKShareLink? - ios

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
NSURL *imageURL =
[NSURL URLWithString:#"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];
content.contentDescription=#"This is facebook test";
content.contentTitle=#"Hello";
content.imageURL=imageURL;
FBSDKShareButton *shareButton = [[FBSDKShareButton alloc] init];
shareButton.shareContent = content;
shareButton.center = self.view.center;
[self.view addSubview:shareButton];
I used facebook-ios-sdk-3.24.0.pkg and I am using the above code for link sharing on facebook using fbsdksharekit. This code is working fine but after closing the xcode and reopen that xcode6.0 it shows the below error.
FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h not found.
i import those frameworks i.e FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h to viewcontroller.m file .
can any one tell me what is the problem.Thanks in advance.

Use the Below Code to Share on Facebook, download latest Facebook SDK
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
NSURL *imageURL =
[NSURL URLWithString:#"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];
content.contentDescription=#"This is facebook test";
content.contentTitle=#"Hello";
content.imageURL=imageURL;
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];

Related

FBSDKShareLinkContent without deep linking to app

I'm using FBSDKShareLinkContent to display a dialog to share a link to Facebook. No matter the link I use (I even tried with https://google.com/) when the post / link is tapped in the Facebook app my app is launched.
I want, however, to load the link in a web browser or the FB browser instead (and not have it launch my app or navigate to the app store). Is there anyway to achieve this? I tried both FBSDKShareDialogModeFeedWeb and FBSDKShareDialogModeAutomatic.
Here is my current code:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://google.com/"];
FBSDKShareDialog* dialog = [[FBSDKShareDialog alloc] init];
dialog.mode = FBSDKShareDialogModeFeedWeb;
dialog.shareContent = content;
dialog.fromViewController = self;
[dialog show];
Add this to your code:
FBSDKShareLinkContent *content1 = [[FBSDKShareLinkContent alloc] init];
content1.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
content1.contentTitle=#"Share";
[FBSDKShareDialog showFromViewController:self withContent:content1 delegate:nil];

FBSDKShareLinkContent not working for few links on iOS

Our app has functionality where user can share the posts from one of our FB page feed.
It works perfectly fine for any kind of link if device has FB native app installed but if it doesn't then it only works for few links. I couldn't understand why it is happening.
Link works successfully:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://www.facebook.com/bigfishgames/videos/10154487015659966/"];
Link not working:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://www.facebook.com/bigfishgames/photos/a.89705929965.104855.10172494965/10154513459844966/?type=3"];
All right, after filing bug to facebook they have fixed this issue.

FBSDKMessageDialog for iOS doesn't work

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:APPSTORE_URL_MAIN];
content.contentTitle = INVITE_TITLE;
content.imageURL = [NSURL URLWithString:INVITE_IMG_URL];
content.contentDescription = INVITE_TEXT;
[FBSDKMessageDialog showWithContent:content delegate:self];
If the Facebook Messenger app is closed, this just opens the app and does nothing else.
Works fine is the FB Messenger app is working in background
Issue resolved by Facebook Developers.

FBSharebutton always opens sharedialog in webview

i am implementing FBShareButton in my project,but share dialog always opens WebView/Safari View instead of facebook native app.I am using facebook SDK 4.6 & xcode 7..when i use share dialog separately it opens in app, but when i use FBShareButton to open share dialog it always opens in web view..here is my code
-(void)openFacebookDialog
{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL
URLWithString:#"https://www.facebook.com/FacebookDevelopers"];
FBSDKShareButton *shareButton = [[FBSDKShareButton alloc] init];
shareButton.shareContent = content;
shareButton.center = self.view.center;
[self.view addSubview:shareButton];
}

Open Facebook app with predefined text to share

Please take a look at this piece of code:
NSString *text = [NSString stringWithFormat:#"%#",
[#"Hello world!" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *post = [NSString stringWithFormat:#"fb://publish/profile/me?text=%#", text];
NSURL* url = [NSURL URLWithString:post];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
By means of this code I would like to open Facebook app installed on the device and open it on a share dialog with the text string used as a predefined text to share. But unfortunately what it does is just open my timeline. What am I doing wrong? Or is it even possible? I can't find any documentation or tutorial on how to do that properly. Thanks
There is simple way using FacebookSDK's framework. This takes only 2 minutes to go.
FBSDKCoreKit.framework
FBSDKShareKit.framework
If in your device facebook app is not installed then this will open default web browser.
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
// in viewdidload or somewhere else
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = #"Scare Prank";
content.contentDescription = #"Someone just got Scare Pranked with ♫";
content.contentURL = [NSURL URLWithString:soundUrl];
content.imageURL = [NSURL URLWithString:#“some icon url”];
FBSDKShareButton *button = [[FBSDKShareButton alloc] initWithFrame:CGRectMake(0, 0, 200, 43)];
button.center = self.center;
button.shareContent = content;
[self addSubview:button];

Resources