Pregunta

I cannot get social frameworks to function correctly on my ios device, however it functions perfectly in the iOS simulator but not on my iPad, can anyone advise on where I may have gone wrong. Thanks in advance.

- (IBAction)sharefb:(id)sender {

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {


    mySLComposerSheet = [[SLComposeViewController alloc] init];

    mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [mySLComposerSheet setInitialText:@"Share this app with your friends"];

    [mySLComposerSheet addImage: [UIImage imageNamed:@"icon2.png"]];
    [self presentViewController:  mySLComposerSheet animated:
     YES completion:nil];

     }

[mySLComposerSheet setCompletionHandler:^
 (SLComposeViewControllerResult result) {


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


     switch (result) {
         case SLComposeViewControllerResultCancelled:
             output = @"Post Cancelled";
             break;
           case SLComposeViewControllerResultDone:
             output = @"Posted successfully";
             break;

         default:
             break;
     }



 }];
¿Fue útil?

Solución

I just copy/pasted your code into a blank project and ran it on my iPad successfully, so I'm not exactly sure what the problem is but here's a couple of things you can try.

First, you use both of these lines in your code:

mySLComposerSheet = [[SLComposeViewController alloc] init];

mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

It is unnecessary, and unwise to call alloc/init on the composer right before composeViewControllerForServiceType which returns a SLComposeViewController object already. Omitting the first of those two lines could solve the problem.

Second, are you sure that "icon2.png" exists in the project? This shouldn't be causing the problem, but hey crazier things have happened.

Third, also unlikely but it is possible that you have some strange invisibles creating problems with the arguments of presentViewController due to your spacing and line break placement. Try rewriting the line to look like this:

[self presentViewController:mySLComposerSheet animated:YES completion:nil];

Site note, your NSString *output is creating a memory leak, unless it is used for something else that you haven't included in your code. This is all going off of your original post which does not actually specify the problem. If you can be more specific, I can probably be more helpful.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top