我正在开发一款iOs 5应用程序(在应用商店中查看),该应用程序最近在iOs 5上与原生Twitter集成。我使用这个代码来拍摄应用程序的屏幕截图:
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");
`
我希望用户可以在Twitter上自动分享屏幕截图。在Twitter上分享我使用的是:
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];
};
我怎样才能把这两个代码融合在一起。我的意思是,当按下一个按钮时,进行屏幕捕捉,保留它,并在上面的本地推特上分享。谢谢
您可以按照它们现在的顺序将它们放在一起。在addImage:
-方法中,指向image
,它应该可以正常工作。您的第一个代码创建了一个UIImage
并将其存储到用户的光库中,因此您可以在下面的twitter代码中使用UIImage
。