如何在iphone sdk中获取谷歌驱动器的inbuild库 [英] How to get the inbuild library for google drive in iphone sdk

查看:157
本文介绍了如何在iphone sdk中获取谷歌驱动器的inbuild库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我想制作一个应用程序,我将数据存储在Google云端硬盘中。
我已经生成了客户端ID和客户端密钥。现在你无法找到谷歌硬盘的inbuild库。

I am struck in a problem that I want to make an app in which I am storing data in Google Drive. I have generated the client id and client secret key. Now U am not able to find out the inbuild library for the google drive.

在哪里拖动GTL.xcodeproj以及什么是GTLDrive.h和GTLDrive_Sources.m。

And where to drag GTL.xcodeproj and what is GTLDrive.h and GTLDrive_Sources.m.

如何使用这个以及在哪里得到这个????

How to use this and where to get this????

这是我将使用的代码:

#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "GTMOAuth2ViewControllerTouch.h"
#import "GTLDrive.h"
@interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, retain) GTLServiceDrive *driveService;
@end


#import "ViewController.h"
static NSString *const kKeychainItemName = @"Google Drive Quickstart";
static NSString *const kClientID = @"YOUR_CLIENT_ID";
static NSString *const kClientSecret = @"YOUR_CLIENT_SECRET";


@implementation ViewController

@synthesize driveService;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Initialize the drive service & load existing credentials from the keychain if available
    self.driveService = [[GTLServiceDrive alloc] init];
    self.driveService.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
                                                                                         clientID:kClientID
                                                                                     clientSecret:kClientSecret];
}

- (void)viewDidAppear:(BOOL)animated
{
    // Always display the camera UI.
    [self showCamera];
}

- (void)showCamera
{
    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    else
    {
        // In case we're running the iPhone simulator, fall back on the photo library instead.
        cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        {
            [self showAlert:@"Error" message:@"Sorry, iPad Simulator not supported!"];
            return;
        }
    };
    cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
    cameraUI.allowsEditing = YES;
    cameraUI.delegate = self;
    [self presentModalViewController:cameraUI animated:YES];

    if (![self isAuthorized])
    {
        // Not yet authorized, request authorization and push the login UI onto the navigation stack.
        [cameraUI pushViewController:[self createAuthController] animated:YES];
    }
}

// Handle selection of an image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
    [self uploadPhoto:image];}

    // Handle cancel from image picker/camera.
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissModalViewControllerAnimated:YES];}

    // Helper to check if user is authorized
    - (BOOL)isAuthorized{
    return [((GTMOAuth2Authentication *)self.driveService.authorizer) canAuthorize];
}

// Handle completion of the authorization process, and updates the Drive service
// 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.driveService.authorizer = nil;
    }
    else
    {
        self.driveService.authorizer = authResult;
    }
}

// Uploads a photo to Google Drive
- (void)uploadPhoto:(UIImage*)image
{
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];

    GTLDriveFile *file = [GTLDriveFile object];
    file.title = [dateFormat stringFromDate:[NSDate date]];
    file.descriptionProperty = @"Uploaded from the Google Drive iOS Quickstart";
    file.mimeType = @"image/png";

    NSData *data = UIImagePNGRepresentation((UIImage *)image);
    GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                       uploadParameters:uploadParameters];

    UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];

    [self.driveService executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveFile *insertedFile, NSError *error) {
            [waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
            if (error == nil)
            {
                NSLog(@"File ID: %@", insertedFile.identifier);
                [self showAlert:@"Google Drive" message:@"File saved!"];
            }
            else
            {
                NSLog(@"An error occurred: %@", error);
                [self showAlert:@"Google Drive" message:@"Sorry, an error occurred!"];
            }
        }];
}

// Helper for showing a wait indicator in a popup
- (UIAlertView*)showWaitIndicator:(NSString *)title
{
    UIAlertView *progressAlert;
    progressAlert = [[UIAlertView alloc] initWithTitle:title
                                               message:@"Please wait..."
                                              delegate:nil
                                     cancelButtonTitle:nil
                                     otherButtonTitles:nil];
    [progressAlert show];

    UIActivityIndicatorView *activityView;
    activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityView.center = CGPointMake(progressAlert.bounds.size.width / 2,
                                      progressAlert.bounds.size.height - 45);

    [progressAlert addSubview:activityView];
    [activityView startAnimating];
    return progressAlert;
}

// 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

我从这里得到了这段代码链接: https://developers.google.com/drive/quickstart-ios

I got this code from this link: https://developers.google.com/drive/quickstart-ios

推荐答案

使用此视频,他如何跟随步骤以及他拖动GTL.xcodeproj的位置。
非常谨慎地遵循这些步骤。

Use this video, how he following steps and where he dragging GTL.xcodeproj. Follow the Steps very carefully.

这篇关于如何在iphone sdk中获取谷歌驱动器的inbuild库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆