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

I want to post something to facebook without an image, but when I write with the image, it did not work and did not report an error. But when I add an image with my message, it will post the message successfully. All I want to publish is without image. Is there any way to do this.

+4
source share
1 answer

try to get rid of the alloc and init string SLComposeViewController, because you recreate with the class method composeViewControllerForServiceType, which returns an object with auto-implementation ..... (if in ARC)

So it will 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 good to me if you are not doing something with this instance of mySocialComposer somewhere else

+2
source

Source: https://habr.com/ru/post/1437795/