在新的xcode4.5中,我们发现要在社交网络中共享的新类SLComposeViewController,我正在阅读类参考,但我仍然不明白如何进行实现.
所以,如果您有任何想法,那将会非常有帮助.谢谢
对不起,我只是找到了.这里是:
您需要将Social.framework添加到项目中.将以下#import"Social/Social.h"添加到您的文件中
您可以创建3种类型的服务:
SLServiceTypeTwitter
SLServiceTypeFacebook
SLServiceTypeSinaWeibo
Run Code Online (Sandbox Code Playgroud)
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];
}
Run Code Online (Sandbox Code Playgroud)
希望这个对你有帮助.如果您想要其他社交网络,请更改SLServiceTypeFacebook以获取其他任何社交网络.
| 归档时间: |
|
| 查看次数: |
3437 次 |
| 最近记录: |