Facebook SDK for iOS 6.0 native Share dialog - ios

I've include the Facebook native Share dialog in my iOS app to let users share some data. The problem is, that the dialog does not open. Here is the code. Also, it is normal for me to pass URL of image to the method? Maybe, this is the problem?
BOOL displayedNativeDialog =
[FBNativeDialogs
presentShareDialogModallyFrom:self
initialText:activityName
image:activityImageURL
url:activityURL
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
NSLOG(#"Error occured");
} else {
if (result == FBNativeDialogResultSucceeded) {
NSLOG(#"Success");
} else {
NSLOG(#"No success");
}
}
}];
if (!displayedNativeDialog) {
NSLOG("Window does notdisplayed");
}

Instead of
image:activityImageURL
pass the UIImage data to image
image:[UIImage imageWithNamed:#"blahblah"]

You can use Native Dialogs only when the user has the Facebook App installed. First check if the facebook app is available, then either display the native dialog or display the web dialog accordingly:
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
shareParams.link = [NSURL URLWithString:#"http://some-url.com"];
shareParams.name = #"Post Name";
shareParams.picture= [NSURL URLWithString:someImageURL];
shareParams.description = #"Post Description";
if ([FBDialogs canPresentShareDialogWithParams:shareParams])
{
[FBDialogs presentShareDialogWithParams:shareParams
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
NSLog(#"%#", [error localizedDescription]);
}];
}
else
{
NSDictionary *params = #{
#"name" : shareParams.name,
#"description" : shareParams.description,
#"picture" : objectiveCharacterImageURL,
#"link" : linkURL
};
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
}];
}

Related

Intigration With Facebook in iOS using facebook sdk

I am trying to post image in imageview(display_image) on user's profile by using facebook SDk.Code is Like below.
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:#"https://developers.facebook.com/docs/ios/share/"];
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
// Present share dialog
[FBDialogs presentShareDialogWithLink:params.link
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
// Success
NSLog(#"result %#", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_display.image, #"picture", #"hello",#"caption",nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
}
it's working good with out sending image value in params dictionary. Using image app will crash here with below error
reason: '-[UIImage length]: unrecognized selector sent to instance 0x7fdd5a80e160'
can any one help me to solve this problem?
Thanks
You cannot post image you can only post image URL Example:-
-(void)fbShare{
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialog]) {
NSURL *imageURL = [NSURL URLWithString:#"https://profile_VMGhBTJVM5_1413618023060.jpg"];
[FBDialogs presentShareDialogWithLink:[NSURL URLWithString:#"http://www.Testinfo.com/"] name:#"name related to link" caption:nil description:#"Testing Desc" picture:imageURL clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
// Success
NSLog(#"result %#", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
// FALLBACK: publish just a link using the Feed dialog
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"testing name", #"name",
#"Testing caption.", #"caption",
#"Desc.", #"description",
#"http://www.Testinfo.com/", #"link",
#"https://profile_VMGhBTJVM5_1413618023060.jpg", #"picture",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
}
}

Post text status/Post simple text on wall with Facebook SDK on iOS

I m using FacebookSDK for iOS v3.12.0.
I try to post simple text on user's wall:
if ([FBDialogs canPresentShareDialogWithParams:params]) {
[FBDialogs presentShareDialogWithLink:nil
name:#"name"
caption:#"caption"
description:#"description"
picture:nil
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
} else {
}
}];
} else {
NSMutableDictionary *paramsDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"name", #"name",
#"caption", #"caption",
#"description", #"description",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:paramsDict
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User cancelled.");
}
}
}];
}
Because I add nil link parameter, Facebook framework does nothing.
How can I post simple text on user's wall?
And I've seen the documentations already (seen this)
You can't pre-fill the details, so if you're not sharing a link or a picture, it looks like you can only call it like this:
[FBDialogs presentShareDialogWithLink:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
They'll get a dialog where they can post a status update.

Facebook invitation to my app not working

I used following code to invite a friend to my app:
NSString *facebookID = user.id;
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:#"to"];
NSString *message = #"SOME_MESSAGE";
NSString *title = #"TITLE";
FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com
[FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
message:message
title:title
parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (!error) {
NSLog(#"Succees:%#",resultURL);
}
}]; }
Opens WebDialog as shown:
But I see no invitation on my profile. How do I get it done properly?
str_id = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"id"];
str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"name"];
str_link = #"www.google.com";
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : #"",
#"link" : str_link,
#"to":str_id,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
[self.indicator stopAnimating];
you didn't mention if the console printed "Success...." or not.
anyway, if the request is successfull users will see it only on fb mobile app

Facebook Share Dialog in iOS

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.
- (IBAction)shareButtonClicked:(id)sender
{
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
NSString *str_img = [NSString stringWithFormat:#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
NSDictionary *params = #{
#"name" :[NSString stringWithFormat:#"Facebook SDK for iOS"],
#"caption" : #"Build great Apps",
#"description" :#"Welcome to iOS world",
#"picture" : str_img,
#"link" : #"",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
//NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
//NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
//NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
}
}];
return;
}
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 :
Tip 1: What if people don't have the Facebook app installed?
The Share dialog can't be displayed if people don't have the Facebook app installed. Apps can detect this by calling [FBDialogs canPresentShareDialogWithParams:nil]; and may disable or hide a sharing button or fall back to the Feed dialog to share on the web. See the HelloFacebookSample included with the iOS SDK for an example.
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 :
if ([FBDialogs canPresentShareDialogWithParams:nil]) {
NSURL* url = [NSURL URLWithString:link.url];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success");
}
}];
}
2.For OpenGraph calls :
id<FBGraphObject> pictureObject =
[FBGraphObject openGraphObjectForPostWithType:#"your_namespace:picture"
title:image.title
image:image.thumbnailUrl
url:image.url
description:#""];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:pictureObject forKey:#"picture"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"your_namespace:action_name"
previewPropertyName:#"picture"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success");
}
}];
Check out other ways to share on iOS here
Hope this helps.
This works for me:
NSString *url = #"myUrl";
FBLinkShareParams* params = [[FBLinkShareParams alloc]init];
params.link = [NSURL URLWithString:url];
if([FBDialogs canPresentShareDialogWithParams:params]){
[FBDialogs presentShareDialogWithLink: [NSURL URLWithString:url]
name: #"Name"
caption: #"Caption"
description: #"Description"
picture: nil
clientState: nil
handler: nil];
}
else{
[...]
}
- (IBAction)btn_facebook:(id)sender {
[self performSelector:#selector(fb_func) withObject:nil afterDelay:0.0];
}
-(void)fb_func
{
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
NSString *str_link = #"";
NSLog(#"%#",str_link);
NSDictionary *params = #{
#"name" :#"name",
#"caption" : #"Description",
#"description" :#"test",
#"picture" : PostimageToPintresrAndFacebook,
#"link" : #"url",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"Story published.");
}
}}];
}
}];
return;
}

How to share multiple post on friend's wall in objective C

I'm using facebook sdk to post on friend's wall. I am able to post it but when i select multiple friends in FBWebDialog instead of posting two friends simultaneously for each friend a separate dialog box is shown. How to post on multiple friend's wall .
-(void)showFriendsList
{
friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
friendPickerController.delegate = self;
[friendPickerController loadData];
}
-(IBAction)facebookShare:(UIButton *)sender
{
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *sender, BOOL donePressed) {
if (!donePressed)
{
return;
}
NSString* fid;
NSString* fbUserName;
for (id<FBGraphUser> user in friendPickerController.selection)
{
NSLog(#"\nuser=%#\n", user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:remedyLabel, #"caption", appIcon, #"picture",symptomName, #"name",remedyDescription,#"description",fid,#"tags",fid,#"to",#"106377336067638",#"place", nil];
NSLog(#"\nparams=%#\n", params);
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed",fid] parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
NSLog(#"Error publishing story.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
//Tell the user that it worked.
NSLog(#"Request Sent");
}
}
}];
}];
}
}];
}
No, that's not possible. You have to open separate dialog for each friend.

Resources