I’m developing a iOs 5 app (View in App Store) with native Twitter integration recent on iOs 5. I’m using this code for taking a screen capture of the app:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
// retrieve the current graphics context
CGContextRef context = UIGraphicsGetCurrentContext();
// render view into context
[self.view.layer renderInContext:context];
// create image from context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// save image to photo album
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:didFinishSavingWithError:contextInfo:),
@"image.png");
`
I would like that the user could automatically share on Twitter the screen capture. For sharing on Twitter I’m using that:
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:[NSString stringWithFormat:@"Final score %@: %d vs. %@: %d ",intnomlocal, puntsl, intnomvisitant, puntsv]];
//[twitter addImage:[UIImage imageNamed:@"image"]];
//[twitter addURL:[NSURL URLWithString:@"http://www.erwinzwart.com"]];
[self presentViewController:twitter animated:YES completion:nil];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if(res == TWTweetComposeViewControllerResultDone)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Done!" message:@"Your tweet was send" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}else if(res == TWTweetComposeViewControllerResultCancelled)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Cancelled" message:@"Your tweet wasn't send" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
[self dismissModalViewControllerAnimated:YES];
};
How can I fuse those two codes. I mean, that when a button pressed, make screen capture, retain it and share it on the native Twitter above. Thanks!!!
You can just put them under each other, in the order they are now. In the
addImage:-method, point toimage, and it should work just fine. Your first code creates aUIImageand stores it to the users photolibrary, so you can use theUIImagein the twitter-code below.