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?

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

This is almost the same answer as llario, but follows Apple docs instructions and employs defensive coding with some additional error checking.

#import <Social/Social.h>

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    if (composeViewController) {
        [composeViewController addImage:[UIImage imageNamed:@"MyImage"]];
        [composeViewController addURL:[NSURL URLWithString:@"http://www.google.com"]];
        NSString *initialTextString = @"Check out this Tweet!";
        [composeViewController setInitialText:initialTextString];
        [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
            if (result == SLComposeViewControllerResultDone) {
                NSLog(@"Posted");
            } else if (result == SLComposeViewControllerResultCancelled) {
                NSLog(@"Post Cancelled");
            } else {
                NSLog(@"Post Failed");
            }
        }];
        [self presentViewController:composeViewController animated:YES completion:nil];
    }
}

Need Your Help

generalised insert into sqlalchemy using dictionary

python dictionary flask sqlalchemy

I'm building an application in Flask and I have several SQLAlchemy models defined. I have a dictionary with key/value pairs for each of the model types.

Purpose of private members in a class

language-agnostic class oop private-members

What are the purposes of having private/protected members of a class/structure in object-oriented programming? What's the harm in having all members be public?