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];
    }];


}

I want to post something on Facebook without image but when I post with image it didn't work and give an error alert. But when I add an image with my post it will post successfully. All I want I to post without image. Is there any way to do that.?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Usman
  • 61
  • 2
  • 8
  • The second time you did it was your internet on/working. Does this continuously happen after you press the button more than once? – MCKapur Oct 04 '12 at 12:27
  • yes internet was working and after one press it happens continuously.. – Usman Oct 04 '12 at 12:33
  • try getting rid of the alloc and init line of SLComposeViewController, because you are recreating with the class method composeViewControllerForServiceType which returns an autoreleased object ..... – MCKapur Oct 04 '12 at 12:58
  • i did that too but i am getting the same issue. And error message aswell. ": CGImageCreate: invalid image size: 0 x 0." – Usman Oct 05 '12 at 07:52

1 Answers1

2

try getting rid of the alloc and init line of SLComposeViewController, because you are recreating with the class method composeViewControllerForServiceType which returns an autoreleased object ..... (Unless under ARC)

So it would look like this:

-(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];
}];

Otherwise the code looks fine to me, unless you are doing something with this mySocialComposer instance somewhere else

MCKapur
  • 9,127
  • 9
  • 58
  • 101
  • Cheers null . I am not using arc. But i found the problem that i am not adding image with that if i add image with that it works fine for multiple times. But i don't want to add image with that so is there any way i can do this without adding image :) – Usman Oct 05 '12 at 05:02
  • Check out this tutorial:http://stackoverflow.com/questions/12503287/tutorial-for-slcomposeviewcontroller-sharing – MCKapur Oct 05 '12 at 07:56
  • Null its the same tutorial that i have followed. My problem is that i wanted to do the post without any image or url .In order to do that i comment out [mySLComposerSheet addImage:[UIImage imageNamed:@"image"]]; [mySLComposerSheet addURL:[NSURL URLWithString:@"http://facebook.com"]]; And while doing that I have got the error : CGImageCreate: invalid image size: 0 x 0. in console. – Usman Oct 05 '12 at 11:50