Failed to post image to facebook using SLComposeViewController?

I would like to post an image to facebook and twitter. I'm fine with Twitter but not facebook using the SLComposeViewController class. Without adding an image, I can post the text and url to facebook. The problem is that when I use add image, I was unable to post this image as well as text, url. SLComposeViewController shows image, text and url on submit. I have the correct appId and I didn't get any errors. But the problem still exists. I don't know where the problem is. Please help me.

    - (void)performFBRequestUploadForImage{

        [self showListOfFaceBookAccountsFromStore];
                if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
            {
                SLComposeViewController *mySLComposerSheet = [SLComposeViewController         composeViewControllerForServiceType:SLServiceTypeFacebook];

                 SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

                     NSString *output;
                    switch (result) {
                        case SLComposeViewControllerResultCancelled:
                            output = @"ACtionCancelled";
                            break;
                        case SLComposeViewControllerResultDone:
                            output = @"Post Successfull";
                            [self dismissViewControllerAnimated:YES completion:nil];
                            break;
                        default:
                            break;
                    }
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Face Book Message" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                    [alert show];
                 };

                [mySLComposerSheet addImage:[UIImage imageNamed:@"images4.jpg"]];
                [mySLComposerSheet setInitialText:@"I am developer."];
                [mySLComposerSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com/"]];
                [mySLComposerSheet setCompletionHandler:completionHandler];
                [self presentViewController:mySLComposerSheet animated:YES completion:nil];
            }

    }

- (void)showListOfFaceBookAccountsFromStore
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


    if( [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] )
    {

        NSDictionary *options = @{
        @"ACFacebookAppIdKey" : myAppId,
        @"ACFacebookPermissionsKey" : @[@"publish_stream"],
        @"ACFacebookAudienceKey" : ACFacebookAudienceFriends};
        [accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error){
            if(granted) {
                ACAccount * account = [[accountStore accountsWithAccountType:accountType] lastObject];
                NSLog(@"Facebook user: %@",[account username]);
                if([account username]==NULL){
                    [self facebookAlert];
                } else {



                }

            }
            else{
                  NSLog(@"Read permission error: %@", [error localizedDescription]);
            }
        }];
    } else {
        [self facebookAlert];
    }
}

      

+3


source to share


3 answers


I used below code in my projects to post image which works great.

    if([SLComposeViewController instanceMethodForSelector:@selector(isAvailableForServiceType)] != nil)
    {
        if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
        {

            SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

            SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
                if (result == SLComposeViewControllerResultCancelled) {

                    NSLog(@"Cancelled");

                } else

                {
                    NSLog(@"Done");
                }

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

            [controller setInitialText:@"Check out my Christmas Gift!"];
            [controller addImage:@"gift.jpg"];

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

        }

      

You just try to follow below tutorials



2. Tutorial 2

+2


source


I checked the internet and noticed several discussions in the last 1 or 2 days related to this issue and they seem to be related to the Facebook bug. So if your posts and images with code are successfully streaming to Twitter, then don't worry! you are doing right.

https://stackoverflow.com/questions/14868518/sharekit-not-sharing-link-to-facebook/



https://discussions.apple.com/thread/4805777

+1


source


  I have resolved through open present-view controller in navigation-bar.it may help you.

 SLComposeViewController *controller = [SLComposeViewController   composeViewControllerForServiceType:SLServiceTypeFacebook];
    [controller setInitialText:shareFrom];
    [controller addImage:self.photoImageView.image];
    [controller addURL:[NSURL URLWithString:dayCareWebsite]];
    dispatch_async(dispatch_get_main_queue(), ^ {

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

    });

      

0


source







All Articles