我使用 social.framework 为 Titanium Appcelerator 创建了共享模块。以下是我的代码:
- (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];
}
}
我只需要打电话SharePost
,它会做所有的事情。这是唯一同时在 Twitter 和 Facebook 上共享的代码。但是当我在 Facebook 上分享一些 URL 时,对话框会正确显示,当我选择 时POST
,它会在一些(大约 5)秒后给我错误。出现以下错误
无法发布到 Facebook - 无法发送帖子,因为与 Facebook 的连接失败。
And from that error, the same can be posted successfully when "Try Again" is selected. 我在这里附上了截图。
如果你们中的任何人有任何线索,请告诉我。