SLComposeViewController

时间:2012-10-04 12:15:23

标签: iphone ios facebook social

-(IBAction)post:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    mySocialComposer = [[SLComposeViewController alloc]init];
    mySocialComposer = [SLComposeViewController    
    composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySocialComposer setInitialText:@"Hello World"];
    [mySocialComposer addImage:[IIImage imageNamed:@"myImage.png"]];

    [self presentViewController:mySocialComposer animated:YES completion:nil];
 }

 [mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){

    NSString *outout = [[NSString alloc] init];

    switch (result) {
        case SLComposeViewControllerResultCancelled:
            outout = @"Post Cancled";
            break;
            case SLComposeViewControllerResultDone:
            outout = @"Post Done";

        default:
            break;
    }
    UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"FaceBook"  
    message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [myalertView show];
    }];


}

我想在没有图片的情况下在Facebook上发布内容,但是当我发布图片时,它确实无法正常工作并提供错误警告。但是当我用我的帖子添加图像时,它会成功发布。所有我希望我发布没有图像。有没有办法做到这一点。 ?

1 个答案:

答案 0 :(得分:2)

尝试摆脱SLComposeViewController的alloc和init行,因为你正在使用类方法composeViewControllerForServiceType重新创建,它返回一个自动释放的对象.....(除非在ARC下)

所以它看起来像这样:

-(IBAction)post:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
mySocialComposer = [SLComposeViewController    
composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySocialComposer setInitialText:@"Hello World"];

[self presentViewController:mySocialComposer animated:YES completion:nil];
 }

 [mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){
NSString *outout = [[NSString alloc] init];

switch (result) {
    case SLComposeViewControllerResultCancelled:
        outout = @"Post Cancled";
        break;
        case SLComposeViewControllerResultDone:
        outout = @"Post Done";

    default:
        break;
}
UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"FaceBook"  
message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[myalertView show];
}];

否则代码对我来说很好,除非你在其他地方用mySocialComposer实例做某事