我使用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的连接失败,无法发送帖子。
从该错误中,当选择“再试一次”时,可以成功发布相同的错误。 我在这里附上了截图。
如果你们中的任何人有任何线索,请告诉我。