SLComposeViewController post both image and url ios9
Asked Answered
E

5

13

What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9

    UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText:@"I need your vote"];
    [fbSheet addURL:[NSURL URLWithString:str]];
    [fbSheet addImage:tableViewScreenshot];
Elyse answered 17/10, 2015 at 21:17 Comment(1)
there is not ios9 problem. FB latest api (4.7.x) problemSogdiana
E
2

So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.

Elyse answered 28/10, 2015 at 18:7 Comment(0)
C
6

The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device. enter image description here

And this one is when the Facebook app is not installed on the device

enter image description here

And this is my code:

 SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[controller addURL:[NSURL URLWithString:@"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:@"icon_circle"]];
[controller setInitialText:@"Bhavuk you're great!"];

[self presentViewController:controller animated:YES completion:nil];

So If you want to share everything, better use FB SDK.

Cozy answered 26/10, 2015 at 17:33 Comment(0)
E
2

So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.

Elyse answered 28/10, 2015 at 18:7 Comment(0)
L
1

Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:

SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:@"I need your vote"];
[fbSheet addImage:tableViewScreenshot]; 
Leucopoiesis answered 5/10, 2016 at 9:53 Comment(1)
You can't even add initialText. It will not appear.Pressurize
G
0

It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:

If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.

If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.

For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup

Genseric answered 15/10, 2017 at 0:55 Comment(0)
S
-1

I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.

-(void)shareWithFacebook:(NSString *)message
{
    if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
    {
        NIDINFO(@"Facebook sharing has publish_actions permission");
    }
    else
    {
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager logInWithPublishPermissions:@[@"publish_actions"]
            handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
            {
                NIDERROR(@"Facebook sharing getting publish_actions permission failed: %@", error);
            }
        ];   
    }

    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
                                                                                   @"og:type": @"article",
                                                                                   @"og:title": @"Bloc",
                                                                                   @"og:description": message,
                                                                                   @"og:url": @"http://getonbloc.com/download"
                                                                                       }];




    FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

        // Create the action
    FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:Share" object:object key:@"article"];
    [action setString:@"true" forKey:@"fb:explicitly_shared"];

        // Create the content
    FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
    content.action = action;
    content.previewPropertyName = @"article";

            // Share the content
    FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
    shareAPI.shareContent = content;
    shareAPI.delegate = self;

    NSError *error;
    if([shareAPI validateWithError:&error] == NO)
    {
        NIDERROR(@"Facebook sharing content failed: %@", error);
    }

    [shareAPI share];
}

 #pragma mark - FBSDKSharingDelegate

- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NIDINFO(@"Facebook sharing completed: %@", results);
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NIDERROR(@"Facebook sharing failed: %@", error);
}

- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
    NIDINFO(@"Facebook sharing cancelled.");
}
Sogdiana answered 25/10, 2015 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.