ObjectiveDropbox 1.0.5

ObjectiveDropbox 1.0.5

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2017

Maintained by Mikhail Motyzhenkov.



  • By
  • Mikhail Motyzhenkov

ObjectiveDropbox

Version
License
Platform

The most complete third-party Objective-C SDK for integrating with the Dropbox API v2.

What is it capable of?

Everything what Dropbox HTTP API v2 is capable of (except Dropbox Business API).

Requirements

  • Xcode 7+
  • iOS 8+ (CocoaPods or manual installation)
  • iOS 7+ (manual installation only)

Installation

ObjectiveDropbox is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "ObjectiveDropbox"

Or you can install it manually by copying source files into your project. In this case you should add WebKit.framework with 'Optional' status to your target.

Example project

To run the example project, clone the repo, and run 'ObjectiveDropbox.xcworkspace' from the Example directory.

Usage

Use the following import:

#import "DropboxClient.h"

Then create DropboxClient:

DropboxClient *dropboxClient = [[DropboxClient alloc] initWithAppKey:<DropboxApp key> 
                                redirectURL:<redirectURL> restartAllTasksAfterRelaunch:YES];

I recommend to use 'http://localhost' as redirectURL (don't forget to add it in your Dropbox App page).

If you want to use multiple Dropbox accounts simultaneously create each DropboxClient with this initializer:

DropboxClient *dropboxClient = [[DropboxClient alloc] initWithAppKey:<DropboxApp key> 
                                redirectURL:<redirectURL> 
                                restartAllTasksAfterRelaunch:YES 
                                keychainAccount:<account string>];

Get access token before the first request:
(user will see Dropbox authentication UI on this step)

[dropboxClient getNewTokenWithSuccess:^ { ... } fail:^(NSString * _Nonnull errorSummary) { ... }];

Access token will be saved to user's keychain and restored later. You don't have to call that method if your dropboxClient.accessToken != nil.

If you want to change Dropbox user, use this code:

dropboxClient.accessToken = nil;

And then call [dropboxClient getNewTokenWithSuccess:fail:] again.

Use all Dropbox features like this:

DropboxCommitInfo *commitInfo = [[DropboxCommitInfo alloc] initWithPath:@"/myfile.txt" 
                                mode:[[DropboxWriteMode alloc] initWithOverwrite]];
[dropboxClient.files upload:commitInfo sourceFileUrl:sourceFileURL 
progress:^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"Upload progress %i%%", (int)(100.0 * totalBytesSent/totalBytesExpectedToSend));
} success:^(DropboxFileMetadata * _Nonnull uploadResult) {
    NSLog(@"File uploaded: %@", uploadResult);
} fail:^(DropboxError * _Nonnull error) {
    NSLog(@"Upload failed with error: %@", error);
}];

See DropboxClient.h for all available methods.

Each download/upload method returns a task object. You can cancel, suspend and resume it. Your download/upload tasks will remain active in background (background fetch must be ON in your target's entitlements).

If you want to be a good iOS citizen add these lines to your AppDelegate implementation:

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
{
    NSDictionary *userInfo = @{@"sessionIdentifier": identifier, @"completionHandler": completionHandler};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ObjectiveDropboxBackgroundSessionUpdated" object:nil userInfo:userInfo];
}

Author

Mikhail Motyzhenkov, [email protected]

License

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