我关注 this blog将 GData 设置到我的 ios 项目,构建成功,一切正常,但是当我将 GTMOAuth2ViewControllerTouch View 添加到我的窗口时,它只是显示一个没有任何内容的黑色 View 。在我的项目中构建 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;
}
最佳答案
我通过将 GData 和 OAuth 库类直接添加到我的应用中解决了这个问题
关于objective-c - 在 xcode4 中设置 GData ios 客户端后,无法使用 OAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9037168/