Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 448
Dancer Avatar asked Nov 29 '22 01:11

Dancer


1 Answers

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;
}
like image 183
Ilario Avatar answered Dec 06 '22 15:12

Ilario