iphone – SLComposeViewController

-(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上发布一些内容,但是当我发布图像时,它确实无法正常工作并提供错误警报.但是当我用我的帖子添加图像时,它会成功发布.所有我希望我发布没有图像.有没有办法做到这一点. ?

最佳答案 尝试摆脱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实例

点赞