无法使用SLComposeViewController张贴图片到Facebook的?(Unable

2019-08-16 22:52发布

我想发布图像到Facebook和Twitter。 我很好的叽叽喳喳,但不使用SLComposeViewController类的Facebook。 随着出添加图像,我能够发布文字和网址进入Facebook的。 问题是,当我使用添加图片我无法张贴此图像和文字,网址。 SLComposeViewController显示当我发送图片,文字和网址。 我有正确的appid,我没有得到任何错误。 但问题仍然存在。 我不知道问题出在哪里。 请帮我。

    - (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];
    }
}

Answer 1:

我用下面的代码在我的项目后,它工作正常图像。

    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];

        }

你只是试图按照下面的教程

  1. 教程1

2. 教程2



Answer 2:

我上网查了,并在与此相关的问题,最近1天或2天注意到了一些讨论,他们似乎有关Facebook的错误。 所以,如果你的代码发布消息和图像的成功到Twitter,那么不用担心! 你是做正确。

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

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



Answer 3:

  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];

    });


文章来源: Unable to post image into facebook using SLComposeViewController?