无法使用SLComposeViewController将图像发布到Facebook中? [英] Unable to post image into facebook using SLComposeViewController?

查看:185
本文介绍了无法使用SLComposeViewController将图像发布到Facebook中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像发布到Facebook和Twitter。我很好用twitter,但没有使用SLComposeViewController类的Facebook。有了添加图像,我可以发布文本和网址到Facebook。问题是当我使用添加图像我无法发布此图像,还有文本,网址。当我发送时,SLComposeViewController显示图像,文本和URL。我有正确的appId,我没有得到任何错误。但问题依然存在。我不是问题的地方。请帮助我。

I would like to post image into facebook and twitter. I am fine with twitter but not with facebook using SLComposeViewController class. With out add image i am able to post text and url into facebook. The problem is when i use add image i was unable to post this image and also text, url. SLComposeViewController shows image, text and url when i send. I have correct appId and i did not get any errors. But the problem is still there. I don't 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];
    }
}


推荐答案

使用以下代码在我的项目中发布图像它工作正常。

I used below code in my projects to post the image it works fine.

    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

  1. Tutorial 1

2. 教程2

这篇关于无法使用SLComposeViewController将图像发布到Facebook中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆