首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Facebook中分享我的应用程序的屏幕截图(cocos2D 3.0)

在Facebook中分享我的应用程序的屏幕截图(cocos2D 3.0)
EN

Stack Overflow用户
提问于 2015-05-20 23:00:10
回答 1查看 124关注 0票数 0

我需要在Facebook中分享我的应用程序的屏幕截图(我使用的是Cocos2D 3.0),但代码不起作用:

代码语言:javascript
运行
复制
// 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];
}
EN

回答 1

Stack Overflow用户

发布于 2015-05-21 13:18:23

代码语言:javascript
运行
复制
-(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];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30353449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档