2

我有一个项目使用 Twitter API 来推特用户的高分。该项目是使用 Cocos2d v1.1 编写的,一切正常。我最近使用 Cocos2d v2.0 开始了一个新项目,并尝试使用我其他项目中的相同代码来合并相同的 Twitter 功能,但按下 Tweet 按钮时不会出现视图控制器。下面是我正在使用的代码...

if ([TWTweetComposeViewController canSendTweet]) // Check if twitter is setup and reachable
    {
        CCLOG(@"Can Tweet");
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];

        // set initial text
        NSString *theTweet = @"The message..."];
        [tweetViewController setInitialText:theTweet];

        // setup completion handler
        tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
            if(result == TWTweetComposeViewControllerResultDone) {
                // the user finished composing a tweet

            } else if(result == TWTweetComposeViewControllerResultCancelled) {
                 // the user cancelled composing a tweet
            }
            [viewController dismissViewControllerAnimated:YES completion:nil];
        };

        // present view controller
        [[[CCDirector sharedDirector] openGLView] addSubview:viewController.view];
        [viewController presentViewController:tweetViewController animated:YES completion:nil];

    }
else
{
    // Twitter account not configured, inform the user
    NSLog(@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup");
}

我发现“openGLView”现在已贬值,我已将其替换为“view”。这仍然不起作用。该方法正在射击。我已经包含了一个 CCLOG,它返回字符串“Can Tweet”并出现在输出窗口中。有没有人对如何使它工作有任何建议。如果我需要提供更多信息,请告诉我。

谢谢

4

1 回答 1

1

Use this code in cocos2d 2.0

AppController * app = (((AppController*) [UIApplication sharedApplication].delegate));

        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];

        [tweetViewController setInitialText:string];

        [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {

            dispatch_async(dispatch_get_main_queue(), ^{

                {
                    if (result == TWTweetComposeViewControllerResultDone)
                    {
                        //successful
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"PPTweetSuccessful" object:nil];

                    }
                    else if(result == TWTweetComposeViewControllerResultCancelled)
                    {
                        //Cancelled
                    }
                }

                [app.navController dismissModalViewControllerAnimated:YES];

                [tweetViewController release];
            });

        }];

        [app.navController presentModalViewController:tweetViewController animated:YES];
于 2012-11-28T10:20:04.307 回答