在xcode4中设置GData ios客户端后,无法使用OAuth

时间:2012-01-27 17:03:51

标签: objective-c ios gdata

我按照this blog将GData设置为我的ios项目,构建成功,一切正常,但是当我将GTMOAuth2ViewControllerTouch视图添加到我的窗口时,它只是显示没有任何内容的黑色视图。我项目中构建的GTMOAuth2ViewControllerTouch代码是http://code.google.com/p/gtm-oauth2/的副本。在gtm-oauth2项目中,OAuth是可行的,我不知道为什么相同的代码在我的新项目中无法工作。

我的代码:

GDAppDelegate.h:

@interface GDAppDelegate : UIResponder <UIApplicationDelegate>{
@private
    UIWindow *_window;
    UINavigationController *mNavigationController;
}

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

@end

GDAppDelegate.m:

#import "GDAppDelegate.h"
#import "GData.h"
#import "GTMOAuth2SignIn.h"
#import "GTMOAuth2ViewControllerTouch.h"
@implementation GDAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:nil];
    mainNavigationController.view.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-20);
    [mainNavigationController.navigationBar setBarStyle:UIBarStyleDefault];
    [mainNavigationController setToolbarHidden:YES];

    NSString *keychainItemName = nil;
    NSString *scope = @"https://www.googleapis.com/auth/plus.me";

    NSString *clientID = @"181779079861.apps.googleusercontent.com";//self.clientIDField.text;
    NSString *clientSecret = @"FAIi_4YiI3vAtYi7Xf1nMF7Q";//self.clientSecretField.text;


    SEL finishedSel = @selector(viewController:finishedWithAuth:error:);

    GTMOAuth2ViewControllerTouch *viewController;
    viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope
                                                              clientID:clientID
                                                          clientSecret:clientSecret
                                                      keychainItemName:keychainItemName
                                                              delegate:self
                                                      finishedSelector:finishedSel];

    NSDictionary *params = [NSDictionary dictionaryWithObject:@"en"
                                                       forKey:@"hl"];
    viewController.signIn.additionalAuthorizationParameters = params;

    NSString *html = @"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
    viewController.initialHTMLString = html;


    self.window.rootViewController = viewController;

    [self.window makeKeyAndVisible];

    return YES;
}

2 个答案:

答案 0 :(得分:1)

我通过将GData和OAuth lib类直接添加到我的应用程序

来解决了这个问题

答案 1 :(得分:0)

我遇到了同样的问题,并且必须将GTMOAuth2ViewControllerTouch.xib文件包含在我的主要解决方案中。否则,使用静态库工作正常。

似乎必须将.xib文件复制到应用程序的资源文件夹中,以便加载它们。