问题
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