Cocos2d 2.0 升級後 Twitter 不再工作 (Twitter no longer working after Cocos2d 2.0 upgrade)


問題描述

Cocos2d 2.0 升級後 Twitter 不再工作 (Twitter no longer working after Cocos2d 2.0 upgrade)

I have a project that uses the Twitter API to Tweet the users high score. That project is written using Cocos2d v1.1 and everything is working fine. I recently started a new project using Cocos2d v2.0 and attempted to use the same code from my other project to incorporate the same Twitter functionality but the viewcontroller will not appear when the Tweet button is pressed. Below is the code I'm using...

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");
}

I've discovered that "openGLView" is now depreciated and I have replaced it with "view". This still does not work. The method is firing though. I've included a CCLOG that return the string "Can Tweet" and that is appearing in the output window. Does anyone have any suggestions on how to get this to work. Let me know if I need to provide more information.

Thanks

‑‑‑‑‑

參考解法

方法 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];

(by Dallas PrichardGuru)

參考文件

  1. Twitter no longer working after Cocos2d 2.0 upgrade (CC BY‑SA 3.0/4.0)

#twitter #uiviewcontroller #cocos2d-iphone






相關問題

用於輕鬆創建 Twitter 位置地理坐標的地圖工具? (Map-tool for easily creating Twitter location geo-coordinates?)

PHP Twitter OAuth - 我無法驗證我的帳戶 (PHP Twitter OAuth - I cannot authenticate my account)

如何設置文本光標在 TWTweetComposeViewController 中的位置? (How to set where the text cursor is in TWTweetComposeViewController?)

如何從 Twitter 檢測成功的身份驗證並在此之後運行一些代碼 (How to detect successful authentication from Twitter and run some code after that)

Cocos2d 2.0 升級後 Twitter 不再工作 (Twitter no longer working after Cocos2d 2.0 upgrade)

在 android (eclipse) 中集成 oAuth twitter 時清除共享首選項 (Clearing shared preferences in case of oAuth twitter integration in android (eclipse))

如何在 twitteR R 包的 getUser 中引用變量名? (How to refer a variable name in getUser in twitteR R package?)

使用 twitteR 包提取 Twitter 句柄而不是屏幕名稱? (Extract Twitter Handles instead of Screen Names using twitteR package?)

在白名單 PHP 之後獲取用戶電子郵件 (Get user email afer whitelist PHP)

多久運行一次 cron 來挖掘 Twitter 公共時間線? (How often to run the cron, to mine twitter public timeline?)

如何從 JQuery 發送到 SQL 數據庫? (How to send from JQuery to SQL database?)

使用 facebook、twitter 等進行身份驗證。合而為一! (Authentication with facebook, twitter, etc.. all in one!)







留言討論