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

发布于 2024-12-29 04:02:08 字数 3091 浏览 5 评论 0原文

我关注此博客 将 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;
}

I follow this blog to setup GData to my ios project, build success, everything is ok, but when I add a GTMOAuth2ViewControllerTouch view to my window, it just show a black view without anything. The code built GTMOAuth2ViewControllerTouch in my project was copy from http://code.google.com/p/gtm-oauth2/. In gtm-oauth2 project, the OAuth is work, I don't know why the same code can't work in my new project.

my code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2025-01-05 04:02:08

我通过将 GData 和 OAuth lib 类直接添加到我的应用程序解决了这个问题

I solved this problem by add GData and OAuth lib classes directly to my app

野味少女 2025-01-05 04:02:08

我遇到了同样的问题,必须将 GTMOAuth2ViewControllerTouch.xib 文件包含到我的主要解决方案中。否则,使用静态库效果很好。

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

I had this same problem and had to include the GTMOAuth2ViewControllerTouch.xib file into my main solution. Otherwise, using the static library worked fine.

It seems that the .xib files have to be copied into the app's resources folder so that it can load them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文