Latest 2.1.0
Homepage https://github.com/ConfusedVorlon/HSGoogleDrivePicker
License MIT
Platforms ios 8.0, requires ARC
Dependencies AsyncImageView, GoogleAPIClient/Drive, Google/SignIn, SVPullToRefresh
Authors

A sane and simple file picker for Google Drive.

Google makes it ridiculously painful to select a file from Google Drive.

For many use-cases, all you want is to present a picker, and get a notification when your user has selected a file.

This is the API that Google should have written.

Picker Screenshot

Example

#import "HSDrivePicker.h"


HSDrivePicker *picker=[[HSDrivePicker alloc] initWithSecret:@"YOUR SECRET HERE"];

[picker pickFromViewController:self
                withCompletion:^(HSDriveManager *manager, GTLDriveFile *file) {
                        NSLog(@"selected: %@",file.title);
                    }];

Updating from 1.0 to 2.0

  • Use [[HSDrivePicker alloc]initWithSecret:] instead of [[HSDrivePicker alloc]initWithId:secret:]
  • Follow the ‘Configure the sign in process’ section below

Installing HSGoogleDrivePicker

You can install HSGoogleDrivePicker in your project by using CocoaPods

pod 'HSGoogleDrivePicker', '~> 2.0’

Getting your API keys

  • Follow Google’s guide (Step 1 only).
  • Enable the Drive API permission. (click on ‘APIs and Auth’, ‘APIs’, then search for ‘Drive’)

Configure the sign in process

  1. Open your project configuration: double-click the project name in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.
  2. Click the + button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank.

When completed, your config should look something similar to the following (but with your application-specific values)

Picker Screenshot

  • Handle the url callback in your app delegate

In YourAppDelegate.m

#import "HSDrivePicker.h"


//Depending on which delegate methods you support…

//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 
//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

//this version works from iOS 9 onwards
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary *)options
{
    if ([HSDrivePicker  handleURL:url]) {
        return YES;
    }

//Your code for other callbacks

    return YES;
}

Usage

Create and show the picker

#import "HSDrivePicker.h"


HSDrivePicker *picker=[[HSDrivePicker alloc] initWithSecret:@"YOUR SECRET HERE"];

[picker pickFromViewController:self
                withCompletion:^(HSDriveManager *manager, GTLDriveFile *file) {
                        NSLog(@"selected: %@",file.title);
                    }];

The completion handler returns with a GTLDriveFile which has all the info you need.

To download the file, use


[manager downloadFile:file
               toPath:fullPath
withCompletionHandler:^(NSError *error) {

    if (error)
    {
        NSLog(@"Error downloading");
    }
    else
    {
        NSLog(@"Success");
    }
}];

Status

HSGoogleDrivePicker is simplistic and new, but I’m using it in production code.

I welcome pull requests.

License

HSGoogleDrivePicker is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "HSGoogleDrivePicker",
    "version": "2.1.0",
    "summary": "A sane and simple file picker for Google Drive.",
    "homepage": "https://github.com/ConfusedVorlon/HSGoogleDrivePicker",
    "screenshots": "https://raw.githubusercontent.com/ConfusedVorlon/HSGoogleDrivePicker/master/images/iPadPicker.png",
    "license": "MIT",
    "authors": {
        "Rob": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/ConfusedVorlon/HSGoogleDrivePicker.git",
        "tag": "2.1.0"
    },
    "source_files": "HSGoogleDrivePicker/HSGoogleDrivePicker",
    "requires_arc": true,
    "dependencies": {
        "AsyncImageView": [],
        "GoogleAPIClient/Drive": [],
        "Google/SignIn": [],
        "SVPullToRefresh": []
    }
}

Pin It on Pinterest

Share This