在xcode4中设置GData ios客户端后,无法使用OAuth
我关注此博客 将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过将 GData 和 OAuth lib 类直接添加到我的应用程序解决了这个问题
I solved this problem by add GData and OAuth lib classes directly to my app
我遇到了同样的问题,必须将 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.