Xcode4.5如何与SLComposeViewController共享按钮
问题描述:
在新的xcode4.5我们发现新的类SLComposeViewController在社交网络中分享,我正在阅读类参考,但我仍然不明白如何使实施。Xcode4.5如何与SLComposeViewController共享按钮
所以,如果你有任何想法,这将是非常有益的。谢谢
答
对不起,我只是找到如何。这是:
您需要将Social.framework添加到您的项目。 添加到您的文件中的以下#进口 “社会/ Social.h”
您可以创建3个服务类型:
SLServiceTypeTwitter
SLServiceTypeFacebook
SLServiceTypeSinaWeibo
实例为Facebook。
SLComposeViewController *fbController =
[SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=
^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted....");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Sent"
message:nil
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
break;
}};
[fbController addImage:[UIImage imageNamed:@"your_image.jpg"]];
[fbController setInitialText:@"The initial text you want to send"];
[fbController addURL:[NSURL URLWithString:@"the url you wanna share"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
我希望你觉得这个很有用。 如果您需要其他社交网络,请为其他两个社交网络更改SLServiceTypeFacebook。