我在设置gmail时遇到了问题。有人能告诉我哪里出了问题吗?
指示:
Run the following command to download the library using git:
git clone --recursive https://github.com/google/google-api-objectivec-client.git在命令行中,我导航到项目的根目录并运行该命令。
Open Xcode and create a new workspace named "Quickstart".
Using File > Add Files to "Quickstart"..., add the following project to the workspace that you cloned in the previous step:
google-api-objectivec-client/Source/GTLCore.xcodeproj我没有创建一个新的工作区,我只是使用了现有的工作区。我单击了文件>将文件添加到“收件箱”,并添加了GTLCore.xcodeproj
Create a new iOS > Application > Single View Application project named "QuickstartApp", with the organization "com.example". Set the Language to Objective-C, and when saving the project set the Add to and Group fields to "Quickstart".由于我已经有一个项目,我没有做这个步骤。
Add the following frameworks and libraries to the project's Build Phases > Link Binary with Libraries section:
GTL.framework (from GTLiOSCore target)我点击了我的收件箱项目,选择了构建阶段并添加了GTL.framework。
Change the following Build Settings:
Add the flag GTL_BUILT_AS_FRAMEWORK=1 to Preprocessor Macros.我点击了我的收件箱项目,点击了构建设置,搜索了预处理宏并添加了这一行代码。
Add the file google-api-objectivec-client/Source/OAuth2/Touch/GTMOAuth2ViewTouch.xib to the project's Supporting Files group.我选择了inboxTests >支持文件,右击“将文件添加到收件箱”,但是该文件不在它所在的位置。
/google-api-objectivec-client/Deps/gtm-oauth2/Source/Touch/GTMOAuth2ViewTouch.xib将以下文件添加到QuickstartApp组:
google-api-objectivec-client/Source/Services/Gmail/Generated/GTLGmail_Sources.m
google-api-objectivec-client/Source/Services/Gmail/Generated/GTLGmail.h我右键单击我的收件箱文件夹,并选择'add files to inbox‘,这两个文件都添加到我的收件箱文件夹。
现在,尝试编译,但得到一个错误的'GTLObject.h'file not found
该文件位于步骤3中添加的GTLCore.xcodeproj中,每次添加这些文件时,它都会请求另一个文件。
步骤4:我创建了自己的文件
gmail.h
#ifndef gmail_h
#define gmail_h
#import <UIKit/UIKit.h>
#import "GTL/GTMOAuth2ViewControllerTouch.h"
#import "GTLGmail.h"
@interface gmail : UIViewController
@property (nonatomic, strong) GTLServiceGmail *service;
@property (nonatomic, strong) UITextView *output;
@end
#endif /* gmail_h */复制并粘贴到新文件gmail.m中
#import <Foundation/Foundation.h>
#import "gmail.h"
static NSString *const kKeychainItemName = @"Gmail API";
static NSString *const kClientID = @"this is my key";
@implementation gmail
@synthesize service = _service;
@synthesize output = _output;
// When the view loads, create necessary subviews, and initialize the Gmail API service.
- (void)viewDidLoad {
[super viewDidLoad];
// Create a UITextView to display output.
self.output = [[UITextView alloc] initWithFrame:self.view.bounds];
self.output.editable = false;
self.output.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0);
self.output.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.output];
// Initialize the Gmail API service & load existing credentials from the keychain if available.
self.service = [[GTLServiceGmail alloc] init];
self.service.authorizer =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:nil];
}
// When the view appears, ensure that the Gmail API service is authorized, and perform API calls.
- (void)viewDidAppear:(BOOL)animated {
if (!self.service.authorizer.canAuthorize) {
// Not yet authorized, request authorization by pushing the login UI onto the UI stack.
[self presentViewController:[self createAuthController] animated:YES completion:nil];
} else {
[self fetchLabels];
}
}
// Construct a query and get a list of labels from the user's gmail. Display the
// label name in the UITextView
- (void)fetchLabels {
self.output.text = @"Getting labels...";
GTLQueryGmail *query = [GTLQueryGmail queryForUsersLabelsList];
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}
- (void)displayResultWithTicket:(GTLServiceTicket *)ticket
finishedWithObject:(GTLGmailListLabelsResponse *)labelsResponse
error:(NSError *)error {
if (error == nil) {
NSMutableString *labelString = [[NSMutableString alloc] init];
if (labelsResponse.labels.count > 0) {
[labelString appendString:@"Labels:\n"];
for (GTLGmailLabel *label in labelsResponse.labels) {
[labelString appendFormat:@"%@\n", label.name];
}
} else {
[labelString appendString:@"No labels found."];
}
self.output.text = labelString;
} else {
[self showAlert:@"Error" message:error.localizedDescription];
}
}
// Creates the auth controller for authorizing access to Gmail API.
- (GTMOAuth2ViewControllerTouch *)createAuthController {
GTMOAuth2ViewControllerTouch *authController;
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeGmailReadonly, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:@" "]
clientID:kClientID
clientSecret:nil
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return authController;
}
// Handle completion of the authorization process, and update the Gmail API
// with the new credentials.
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)authResult
error:(NSError *)error {
if (error != nil) {
[self showAlert:@"Authentication Error" message:error.localizedDescription];
self.service.authorizer = nil;
}
else {
self.service.authorizer = authResult;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
// Helper for showing an alert
- (void)showAlert:(NSString *)title message:(NSString *)message {
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
@end发布于 2016-02-03 01:59:24
文档指出,“静态库目标还创建了一个文件夹,其中包含库的标头,以拖动到目标的源中”。对应的目录只包含一个头文件GTLDefines.h,它显然没有引用其他必需的文件,比如GTLObject.h,也没有只包含头文件的文件夹。我认为有必要将其他必需的头文件(如Objects/GTLObject.h )的引用手动添加到app项目中。
也试着看看这个link。这里声明,他将头从GTL.proj导入到他的项目中。这些文件包括GTLBase64.h、GTLBatchQuery.h、GTLBatchResult.h等文件。如果没有头文件,他将获得导入语句上的错误"GTLObject.h文件未找到。“。
https://stackoverflow.com/questions/35161822
复制相似问题