4
-(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 上发布一些内容,但是当我使用图像发布时它不起作用并给出错误警报。但是当我在帖子中添加图片时,它会成功发布。我只希望我发布没有图像。有没有办法做到这一点。?

4

1 回答 1

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地方用这个实例做一些事情

于 2012-10-04T12:59:32.683 回答