0

I am implementing Facebook sharing in my app. It is required to share an image with a description , however once the image tapped or clicked it should be navigated to a web portal.

However this is possible using the feed dialog , but I would like to do this using social framework. Is this possible ?

rustylepord
  • 5,681
  • 6
  • 36
  • 49

4 Answers4

2

With SLComposeViewController, you can't pre-populate a Facebook post for the user. The methods exist in the social framework, but a few years ago Facebook disallowed apps to do this, so even if you use:

BOOL initialTextSet = [fbController setInitialText:@"Check out this article."];

the method will return YES, but the text will not actually get populated.

If you want to have more control over what you are posting, then you'll have to add the Facebook SDK to your project. I actually went that route in an earlier version of my app, but it becomes a pain to maintain. In the end, I just went with the Apple native framework. It's MUCH easier to use than the FB SDK, and it's future-proof. No need to wonder if your next iOS version build suddenly will have a broken Facebook share because the SDK needs to be updated (and it does, often).

Mike Critchley
  • 1,643
  • 15
  • 20
1

Seems like it is impossible to do so this kind of customization. However to achieve the required functionality from the native framework , the webpage url should contain the meta data as described in following post.

how to use og meta tag for facebook share

Community
  • 1
  • 1
rustylepord
  • 5,681
  • 6
  • 36
  • 49
0

Use this

SLComposeViewController * fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
        SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
        case SLComposeViewControllerResultCancelled:
        default:
        {
            NSLog(@"Cancelled.");

        }
            break;
        case SLComposeViewControllerResultDone:
        {
            NSLog(@"Posted.");
        }
            break;
    }};

    [fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Check out this article."];
    [fbController addURL:[NSURL URLWithString:@"URLString"]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
}
Hiren Varu
  • 1,447
  • 1
  • 9
  • 8
  • This will post the URL and image ,however tapping the image does not navigate to the url. It just opens the album , image was posted . – rustylepord Feb 13 '15 at 12:46
0
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

 SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

 SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
 if (result == SLComposeViewControllerResultCancelled)
 {
 DebugLog(@"Cancelled");
 }
 else
 {
 [UIUtils alertView:NSLocalizedString(@"FB POST SUCCEEDED", nil) withTitle:NSLocalizedString(@"SUCCESS", nil)];
 }

 [controller dismissViewControllerAnimated:YES completion:Nil];
 };
 controller.completionHandler =myBlock;

 //Adding the Text to the facebook post value from iOS
 [controller setInitialText:NSLocalizedString(@"SHARE TWITTER", nil)];

 //Adding the URL to the facebook post value from iOS
 //        [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];

 //Adding the Image to the facebook post value from iOS
 [controller addImage:self.crushCardImage];

 [self.view.window.rootViewController presentViewController:controller animated:YES completion:Nil];
 }
 else
 {
 [UIUtils alertView:NSLocalizedString(@"NO FB", nil) withTitle:NSLocalizedString(@"FAILURE", nil)];
 }
}
yoshiiiiiiii
  • 953
  • 8
  • 20
  • This will post the URL and image ,however tapping the image does not navigate to the url. It just opens the album , image was posted . – rustylepord Feb 13 '15 at 12:47