我正在开发iOs 5应用程序(View in App Store),最近在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];
};
如何融合这两个代码。我的意思是,当按下按钮时,进行屏幕捕获,保留并在上面的本地Twitter上共享它。感谢!!!
答案 0 :(得分:0)
您可以按照现在的顺序将它们放在彼此之下。在addImage:
- 方法中,指向image
,它应该可以正常工作。您的第一个代码会创建一个UIImage
并将其存储到用户的photolibrary中,因此您可以使用下面的twitter代码中的UIImage
。