我需要在Facebook上分享我的应用程序的屏幕截图(我使用Cocos2D 3.0),但代码不起作用:
// For take Screenshot of App
-(UIImage *)capture
{
AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
// for retina-display
UIGraphicsBeginImageContextWithOptions(_appDelegate.window.bounds.size, NO, [UIScreen mainScreen].scale);
[_appDelegate.window drawViewHierarchyInRect:_appDelegate.window.bounds afterScreenUpdates:NO];
} else {
// non-retina-display
UIGraphicsBeginImageContext(_appDelegate.window.bounds.size);
[_appDelegate.window drawViewHierarchyInRect:_appDelegate.window.bounds afterScreenUpdates:NO];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
-(void)btnSharedFacebookTapped:(id)sender
{
[self capture];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [self capture];
// photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
}
答案 0 :(得分:0)
-(UIImage*) takeGameScreenshot
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize size = [[CCDirector sharedDirector] viewSize];
CCRenderTexture *renderTxture = [CCRenderTexture renderTextureWithWidth:size.width
height:size.height];
[renderTxture begin];
[[[CCDirector sharedDirector] runningScene] visit];
[renderTxture end];
return [renderTxture getUIImage];
}
-(void)facebookShare:(UIImage*)inImage
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSString *textShare;
textShare = [NSString stringWithFormat:@"Checkout ultimate iPhone game %@ - %@", GAME_NAME, GAME_SHORT_LINK];
[controller setInitialText:textShare];
[controller addImage:inImage];
[self.navController presentViewController:controller animated:YES completion:nil];
}
-(void)shareImage
{
UIImage *resultImage = [self takeGameScreenshot];
[self facebookShare:mResultImage];
}