【问题标题】:Twitter + OAuth + iPhone = fustrationTwitter + OAuth + iPhone = 沮丧
【发布时间】:2011-05-19 14:01:30
【问题描述】:

我正在尝试在我的代码中实现http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master。我正在关注提供的演示,但我似乎无法让它工作。这就是我认为目前的问题所在。

因此,该示例声明了一个处理 OAuth 连接的视图控制器,并且在应用程序委托标头中,如下所示:

应用委托标头:

#import <uikit/uikit.h>

@class OAuthTwitterDemoViewController;

@interface OAuthTwitterDemoAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    OAuthTwitterDemoViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet OAuthTwitterDemoViewController *viewController;

@end

应用委托实现:

@implementation OAuthTwitterDemoAppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    
    [window addSubview:viewController.view]; <------------------------
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end

所以你可以看到箭头所在的位置,我们从不执行 initWithNib 或普通 init,我们只是直接将它的视图添加到窗口。

在 viewController 上调用的是:

OAuthTwitterDemoViewController

- (void) viewDidAppear: (BOOL)animated {
    if (_engine) return;
    _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
    _engine.consumerKey = kOAuthConsumerKey;
    _engine.consumerSecret = kOAuthConsumerSecret;

    [_engine requestRequestToken];

    UIViewController            *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];

    if (controller) 
        [self presentModalViewController: controller animated: YES];
    else {
        [_engine sendUpdate: [NSString stringWithFormat: @"Already Updated. %@", [NSDate date]]];
    }

}

所以基本上在我的示例中它永远不会被调用,但在演示中它确实如此。我很困惑我可能需要做什么才能让它工作。我想知道,因为 viewController 是应用程序委托标头中的 IBOutlet,我可能必须在 Interface Builder 中做一些事情,但我不确定是什么。

任何帮助将不胜感激!!!

【问题讨论】:

  • twitter oauth 中的签名是什么?

标签: iphone


【解决方案1】:

我们只是在演示中使用标准的基于视图的应用程序模板;你在用那个还是别的什么?您的 OAuthTwitterDemoViewController 是否曾经被实例化(即 viewController 在您的 applicationDidFinishLaunching 中有值,还是 0x0:)?

目前尚不清楚您的项目中哪些有效,哪些无效。你能澄清一下吗?

【讨论】:

  • 我使用基于窗口的应用程序模板并将 OAuthTwitterDemoViewController.h/m 文件添加到我的项目中。然后,我在我的应用程序委托中添加了模仿您的应用程序委托以处理 OAuthTwitterDemoViewController 的代码。我会在 applicationDidFinishLaunching 中说 viewController 没有值。我不太确定您在哪里实例化 OAuthTwitterDemoViewController,因为在您的代码中您只是将 viewController.view 添加到窗口中。我错过了一些东西。感谢您回复本帖并提供帮助。
  • 另外,这段代码的作者回复了我的帖子,真是太棒了。
  • 我使用 viewcontroller 模板让它工作。我需要回去重新学习将这些东西连接在一起。谢谢你的帖子。
  • 不客气!操作系统从 xib 文件中实例化 viewController,这就是为什么如果您使用不同的模板,它可能无法工作。
  • 还有一个问题,如果有人想要使用 Twitter+Oauth 的注销功能,他们是否必须以某种方式删除保存的默认值?
猜你喜欢
  • 2011-04-03
  • 1970-01-01
  • 2016-07-07
  • 1970-01-01
  • 2011-05-29
  • 2012-12-17
  • 2015-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多