iosfacebooktwitterslcomposeviewcontroller

IOS7 - SLComposeViewController - Include links / Images?


I'm building an IOS7 Native app on behalf of a client - its for Fitness Instructors.

The brief requests that the clients can socially share progress updates - which include a link to the instructors site to help promotion, for example - 'Joe ran 3000 miles with the help of Debbie Personal Trainer' and ideally a little pic of the trainer.

I've looked at the SLComposeViewController and can easily create the tweet string but I don't know how to add a URL and image to this - does anyone know if its possible?


Solution

  • Import framework <Twitter/Twitter.h> and <Social/Social.h>.

    -(void)sendFacebook:(id)sender {
    
        SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    
        [composeController setInitialText:@"look me"];
        [composeController addImage:[UIImage imageNamed:@"image.png"]];
        [composeController addURL: [NSURL URLWithString:@"http://www.apple.com"]];
    
        [self presentViewController:composeController animated:YES completion:nil];
    
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
                NSLog(@"delete");
            } else  {
                NSLog(@"post");
            }
    
        //    [composeController dismissViewControllerAnimated:YES completion:Nil];
          };
            composeController.completionHandler =myBlock;
    }
    
    - (void)sendTwitter:(id)sender {
    
        SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    
        [composeController setInitialText:@"look me"];
        [composeController addImage:[UIImage imageNamed:@"image.png"]];
        [composeController addURL: [NSURL URLWithString:
                                    @"http://www.apple.com"]];
    
        [self presentViewController:composeController
                           animated:YES completion:nil];
    
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) { 
                NSLog(@"delete"); 
            } else {
                NSLog(@"post");
            }
         //   [composeController dismissViewControllerAnimated:YES completion:Nil];
          };
            composeController.completionHandler =myBlock;
    }