3

我想将图像发布到 facebook 和 twitter。我对 twitter 很好,但对使用 SLComposeViewController 类的 facebook 不满意。没有添加图像,我可以将文本和 url 发布到 facebook。问题是当我使用添加图像时,我无法发布此图像以及文本、网址。SLComposeViewController 在我发送时显示图像、文本和 url。我有正确的 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];
    }
}
4

3 回答 3

2

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

    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

于 2013-02-14T05:55:37.667 回答
1

我检查了互联网,并注意到最近 1 或 2 天有一些与此问题相关的讨论,它们似乎与 Facebook 错误有关。因此,如果您的代码成功将消息和图像发布到 Twitter,请不要担心!你做得对。

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

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

于 2013-02-14T06:24:23.153 回答
0
  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];

    });
于 2015-01-19T07:51:13.063 回答