Unable to share PDF URL on Facebook using SLComposeViewController

旧巷老猫 提交于 2019-12-24 14:34:34

问题


I have created sharing module for Titanium Appcelerator using social.framework. Following is my code:

- (id) Facebook {

//if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
//{
    NSLog(@"Sharing via Facebook", nil);

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText: [dictPost valueForKey: @"post"]];
    [fbSheet addURL: [NSURL URLWithString: [dictPost valueForKey: @"link"]]];

    NSLog(@"Sharing via Facebook 2", nil);

    [[TiApp app] showModalController: fbSheet animated: YES];
    NSLog(@"Sharing via Facebook 3", nil);

/*} else {
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Post can't be shared. Please check Settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil] autorelease];
    [alert show];
}*/
}

- (id) Tweet {
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:SLServiceTypeTwitter];
    [tweetSheet setInitialText: [dictPost valueForKey: @"post"]];
    [[TiApp app] showModalController: tweetSheet animated: YES];
}

- (void) SharePost : (id) args {
    ENSURE_UI_THREAD(SharePost, args);
    ENSURE_UI_THREAD(Tweet, nil);
    ENSURE_UI_THREAD(Facebook, nil);

    NSArray *val = args;
    NSDictionary *dict = [[val objectAtIndex: 0] retain];

    dictPost = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [dict valueForKey: @"post"], [dict valueForKey: @"link"], [dict valueForKey: @"title"], [dict valueForKey: @"image"], nil] forKeys: [NSArray arrayWithObjects: @"post", @"link", @"title", @"image", nil]];

    if ([[dict valueForKey: @"type"] intValue] == 1) {
        [self Tweet];
    } else if ([[dict valueForKey: @"type"] intValue] == 2) {
        [self Facebook];
    }
}

I just need to call SharePost and it will do all the things. This is the only code which shares on both Twitter and Facebook. But when I share some URLs on Facebook, dialog box is displayed proper and when I select POST, it gives me error after some(around 5) seconds. Following error occurs

Cannot Post To Facebook - The post cannot be sent because the connection to Facebook failed.

And from that error, the same can be posted successfully when "Try Again" is selected. I have attached screenshots here.

Please let me know if anyone of you have any clue.

来源:https://stackoverflow.com/questions/20881429/unable-to-share-pdf-url-on-facebook-using-slcomposeviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!