A Dropbox v2 client library written in Objective-C

Overview

TJDropbox

TJDropbox is a Dropbox v2 client library written in Objective-C. When Dropbox originally announced their v2 API they included only a Swift client library, and at the time I wrote TJDropbox as an Objective-C alternative to it to migrate my app Close-up to Dropbox v2. Since then, Dropbox has released an Objective-C v2 SDK. If you’re migrating away from Dropbox’s v1 SDK to v2 and are considering alternatives to Dropbox’s first party solution, TJDropbox is a pretty well featured replacement with no dependencies and very few source files.

Installation

You can use TJDropbox by adding all the source files from the TJDropbox/ directory to your project, or with CocoaPods.

Authenticating

Authentication with TJDropbox is pretty flexible. The simplest way to do it would be to use the provided TJDropboxAuthenticator class.

- (void)authenticate
{
    [TJDropboxAuthenticator authenticateWithClientIdentifier:/*Dropbox client identifier*/
                                         options:/*Options for auth*/
                                                  completion:^(TJDropboxCredential *credential) {
        if (credential) {
            // Auth succeeded, store credential.
        } else {
            // Auth did not succeed.
        }
    }];
}

Be sure to call +tryHandleAuthenticationCallbackWithURL: from your app delegate's -application:openURL:options: method for this to work. TJDropboxAuthenticator attempts auth using the following methods in order of preference.

  1. The Dropbox app (bypassed if bypassNativeAuth is YES in options)
  2. ASWebAuthenticationSession in iOS 12+.
  3. SFAuthenticationSession in iOS 11+.
  4. Auth in Safari.app

That being said, you can also authenticate manually using the utility methods TJDropbox provides. Advanced auth is detailed here.

TJDropbox doesn't store the credentials, that's up to you.

Provided Request Types

Once authenticated, TJDropbox is capable of doing the following things

  • Listing the contents of a folder
  • Downloading files
  • Uploading files
  • Saving files from URLs
  • Moving files (thanks @horseshoe7)
  • Deleting files
  • Getting info about files (thanks @horseshoe7)
  • Getting shareable links to files
  • Getting a user's total space and available space (thanks @onfoot)
  • Creating folders (thanks @blach)

The methods for these are all listed in TJDropbox.h.

Custom Requests

Though TJDropbox only supports a few types of requests for now, internally it has formatters for any Dropbox API request you'd like and handlers for parsing results. Most notably:

  • +apiRequestWithPath:accessToken:parameters: formats RPC requests to the api.dropboxapi.com host.
  • +performAPIRequest:withCompletion: can be used to execute an RPC request.
  • +contentRequestWithPath:accessToken:parameters: formats content requests to the content.dropboxapi.com host.
  • +resultDataForContentRequestResponse: can be used to extract the result API information from a content request.
  • +processResultJSONData:response:error:parsedResult: can be used to process the results from either an RPC or content request.

All the externally exposed methods in TJDropbox are built on top of these utilities, and they can be used to add new functionality to TJDropbox. Requests and pull requests are very welcome!

Architecture notes

  • I wanted to give people who use this library control, which is why auth is largely up to you (though you can use TJDropboxAuthenticationViewController) and storing of tokens is up to you. I don't want to tell you how to manage that stuff, your app may have its own special needs.
  • At the moment, callbacks from TJDropbox methods will come back on threads other than the main thread. That means you'll need to dispatch back to the main thread sometimes, beware!
  • I believe in using boring tech. This is, after all, an Objective-C port of something that there's a Swift version of. There are no external dependencies or craziness, it's just built on top of foundation classes and has little magic to it. I'd prefer to keep it simple.
  • TJDropbox supports iOS 8 and above. It could be modified to support iOS 7 and above, for now the use of NSURLQueryItem is the only thing I think is blocking that.

Todo

  • Better sample project
  • More documentation
  • Carthage support
  • Tests

Apps using TJDropbox

Comments
  • Support new

    Support new" short-lived" token

    Hi, this is not an issue, but not sure where to request a new feature that Dropbox's "short-lived" token.(https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens) The current not expired token is deprecated and will expire Sep. 2021.

    Thanks for making efforts to make this api for Objective-C. Has been using this lib for a long while.

    Thanks!

    VC

    opened by vincechiu 13
  • get_space_usage parameters

    get_space_usage parameters

    I'm about to use TJDropbox for my app and one of the things I will need is ability to retrieve the amount of free space on user's Dropbox. I implemented the get_space_usage API call, although not without additional changes.

    Methods for creating request parameters serialize a nil parameter dictionary as an empty POST body, which is probably not valid JSON content, because by the documentation, get_space_usage requires a "null" value, which definitely is. I could pass an [NSNull null] parameter, but request methods in the library accept a <NSString *, NSString *> dictionary.

    So, we could either change the [TJDropbox parameterStringForParameters] method to pass "null" in case of a nil dictionary (which I did), or change all request methods to accept an id parameter and let NSJSONSerialization serialize anything (which I could do, but don't know if such change has any chance of being accepted for a PR).

    What do you think?

    opened by onfoot 11
  • Support refresh tokens when using app auth

    Support refresh tokens when using app auth

    Hello Tim,

    thanks a lot for your efforts in adding support for the new short lived tokens and refresh tokens.

    It seems however, that TJDropbox's authentication using the iOS Dropbox app doesn't support refresh tokens yet.

    I compared what TJDropbox is doing with what the official Dropbox Objective-C SDK is doing, and could enable refresh tokens using TJDropbox and app auth using two simple modifications.

    This is an example request from TJDropbox:

    dbapi-2://1/connect?k=9gg2zssmv7XXXXX&s=&state=oauth2code:6Y4vUgu9rIRJbx890ry3mwp2ryhwP0u0FOsaZmMrnx8:S256:&extra_query_params=code_challenge%3D6Y4vUgu9rIRJbx890ry3mwp2ryhwP0u0FOsaZmMrnx8%26code_challenge_method%3DS256%26response_type%3Dcode

    This is an example request from the official Dropbox SDK:

    dbapi-2://1/connect?k=9gg2zssmv7XXXXX&s=&state=oauth2code:kiCBUKN79D3O3hGI_eR0y7zikhTW0R7vY_dD-DeuLf4:S256:offline:account_info.read&extra_query_params=code_challenge%3DkiCBUKN79D3O3hGI_eR0y7zikhTW0R7vY_dD-DeuLf4%26code_challenge_method%3DS256%26token_access_type%3Doffline%26response_type%3Dcode%26scope%3Daccount_info.read

    The notable changes are:

    I added both changes to the URL generated in the -[TJDropbox dropboxAppAuthenticationURLWithClientIdentifier:codeVerifier:] method, and could successfully get an access token with a refresh token.

    (Actually, just adding "offline" to the state parameter seems to work, but it's better to do the same as the official SDK and do both changes).

    opened by blach 9
  • Various changes: thread-safety, allow overwriting files, progress for large uploads, isKindOfClass checks, improved SFSafarViewController auth

    Various changes: thread-safety, allow overwriting files, progress for large uploads, isKindOfClass checks, improved SFSafarViewController auth

    Here is a quick overview of various changes I made:

    • make TJDropbox more thread-safe by using serial operation queues
    • download: allow overwriting existing files
    • upload: allow overwriting existing files
    • add support for upload progress block for chunked (large) uploads
    • increase large file upload chunk size to 10 MB - same as used by the official Dropbox Objective-C SDK
    • add isKindOfClass checks when accessing parsed response objects to prevent crashes if the server returns unexpected values
    • Add support for default redirect url for SFSafariViewController-based authentication: it is not necessary (anymore?) to set up a web site that redirects to an app scheme. Instead, you can just directly use the "db-CLIENTIDENTIFIER" app scheme as the redirect URL for SFSafariViewControlle-based auth. The official Dropbox Objective-C SDK does the same. Use +tokenAuthenticationURLWithClientIdentifier: method to create the auth url and +accessTokenFromURL:withClientIdentifier: to parse the response.

    You can find more details in the commit messages. It's up to you if you want to merge these changes, but they were necessary so I could use TJDropbox in my app Textastic.

    opened by blach 9
  • Add CocoaPods support

    Add CocoaPods support

    This is a starter .podspec file for CocoaPods support

    Left to do

    • [ ] get setup with CocoaPods Trunk service (to publish/make it public) @timonus https://guides.cocoapods.org/making/getting-setup-with-trunk.html
    • [x] update README
    opened by ReadmeCritic 8
  • not support ipv6?

    not support ipv6?

    iPad running iOS 9.3.2 and iPhone running iOS 9.3.2 on both Wi-Fi and cellular networks

    IPv6 network, an error was shown when we attempted to sign in with Dropbox.

    “The operation couldn't be completed. (TJDropboxErrorDomain error 0.) ”

    opened by qianbodong 7
  • Chinese support for a problem

    Chinese support for a problem

        NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Dropbox 使用入门.pdf"];
        NSLog(@"%@", path);
        [TJDropbox downloadFileAtPath:@"Dropbox 使用入门.pdf" toPath:path accessToken:self.accessToken completion:^(NSDictionary *_Nullable parsedResponse, NSError *_Nullable error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (error) {
                    NSLog(@"%@ ", [error localizedDescription]);
    

    // self.outputTextView.text = [error description]; } else { NSLog(@"OK "); } }); }];

    [TJDropbox downloadFileAtPath:@"Dropbox 使用入门.pdf"

    or

    [TJDropbox downloadFileAtPath:@"/Dropbox 使用入门.pdf"

    All wrong

    The operation couldn’t be completed. (TJDropboxErrorDomain error 0.)

    opened by qianbodong 6
  • Write `TJDropboxAuthenticator` class that wraps various complicated auth methods.

    Write `TJDropboxAuthenticator` class that wraps various complicated auth methods.

    Current ways you can auth in order of preference are

    • Dropbox app
    • ASWebAuthenticationSession
    • SFAuthenticationSession
    • SFSafariViewController
    • Safari app
    • TJDropboxAuthViewController (should be considered deprecated as it relies on UIWebView.

    Would be nice if there wasn't as much manual work you had to do to make these all "just work" correctly.

    opened by timonus 3
  • Dropbox requests fail with non-ascii encoded paths.  (i.e. unicode characters)

    Dropbox requests fail with non-ascii encoded paths. (i.e. unicode characters)

    I had a user with dropbox files containing the cyrillic alphabet. (i.e. "/Океан Эльзи - Без бою.txt")

    This would fail using the TJDropbox code out of the box. I found a way to ascii-escape these (well, I also see you have a asciiEncodedString: method), but perhaps these should be on every method that has path as an argument? The out-of-the-box code for parameterString... will not ascii-encode these.

    I'm wondering what you'd like to do. You know your code better than I do, so I thought I'd consult first before implementing a definitive fix. I made it work for my app, but it would be nice to get a universal solution in there...

    opened by horseshoe7 3
  • Add support for refresh tokens when using app auth

    Add support for refresh tokens when using app auth

    Use the following authentication options to use native app auth with refresh tokens:

    [[TJDropboxAuthenticationOptions alloc] initWithGenerateRefreshToken:YES bypassNativeAuth:NO]
    
    opened by blach 2
  • Document changes in Safari auth

    Document changes in Safari auth

    https://github.com/timonus/TJDropbox/pull/21/commits/1f198dd6d4e8202e183ce4b5e4068b6828bb8f54 changed how one can auth with SFSafariViewController, the docs need to be updated.

    opened by timonus 2
Releases(0.7)
  • 0.7(Aug 27, 2021)

    • Adds TJDropboxAuthenticator for performing end-to-end auth on iOS and iPadOS (TJDropboxAuthenticationViewController is now deprecated).
    • Support for Dropbox refresh tokens (long lived tokens are being deprecated at the end of September 2021).
    • Adds support for PKCE authentication.
    • Adds ability to revoke access tokens.
    • Adds ability to mute desktop notifications for some actions.
    • Adds search functionality.
    • Uses the delete_v2 and move_v2 endpoints.
    • Improved error handling.
    • Performance improvements.
    Source code(tar.gz)
    Source code(zip)
  • 0.6(Jul 23, 2017)

    • Adds tvOS and watchOS support to the pod spec.
    • Adds utility to help detect if errors are due to invalid Dropbox credentials being used.
    • Fixes issue migrating Dropbox API v1 to v2 tokens.
    • Adds method to get file thumbnails.
    • Exposes internal method that returns requests to download files.
    • Simplifies authentication by dropping need for redirect URLs, client can use a URL scheme they register instead.
    • Adds support for monitoring progress of large file uploads.
    • Allows users to specify "overwrite" upload policy instead of "add".
    • Updates docs to cover SFAuthenticationSession and other new API changes.
    Source code(tar.gz)
    Source code(zip)
  • 0.5(Aug 24, 2016)

    • Add support for saving URL contents to Dropbox.
    • Add support for getting short links and links that are shareable while file uploads are occurring.
    • Add support for monitoring upload and download progress.
    • Add support for fetching authenticated account info.
    • Add CocoaPods support.
    Source code(tar.gz)
    Source code(zip)
  • 0.4(Aug 5, 2016)

    • Add support for moving files.
    • Add support for getting file info.
    • Add support for getting user's used and available space.
    • Add support for large file uploads.
    • Add support for getting deleted files when listing folder contents.
    • Add error handling utility.
    Source code(tar.gz)
    Source code(zip)
  • 0.3(May 29, 2016)

  • 0.2(May 20, 2016)

  • 0.1(Apr 30, 2016)

Owner
Tim Johnsen
iOS at @Instagram, previously at @pinterest, @Flipboard. Side projects as @tijoinc.
Tim Johnsen
A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1

STTwitter A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1 Like a FOSS version of Twitter Fabric TwitterKit, without th

Nicolas Seriot 1k Nov 30, 2022
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022
An easy-to-use Objective-C wrapper for the Uber API (no longer supported)

UberKit UberKit is a simple Objective-C wrapper for the new Uber API . Installation Cocoapods UberKit is available through Cocoapods. To install it, s

Sachin Kesiraju 95 Jun 30, 2022
ObjectiveFlickr, a Flickr API framework for Objective-C

ObjectiveFlickr ObjectiveFlickr is a Flickr API framework designed for Mac and iPhone apps. OAuth Support ObjectiveFlickr now supports Flickr's new OA

Lukhnos Liu 714 Jan 9, 2023
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
Swift client for Unsplash

Unsplash API client written in Swift. Unsplash offers 2 APIs: Source API (unlimited requests) Official API JSON API (5000 requests / hour) JSON API is

Modo 188 Nov 12, 2022
A Slack API Client for the Perfect Server-Side Swift Framework

PerfectSlackAPIClient is an API Client to access the Slack API from your Perfect Server Side Swift application. It is build on top of PerfectAPIClient

Cap.雪ノ下八幡 2 Dec 1, 2019
Wanikani-swift - Unofficial Swift client for the WaniKani API

WaniKani A Swift library and client for the WaniKani REST API. It currently supp

Aaron Sky 5 Oct 28, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
An Elegant Financial Markets Library Written in Swift

Notice As of May 20th, 2017, it appears that Yahoo is dropping support for a few features that BigBoard supports or there is an outage on their end ca

Dalton Hinterscher 66 Dec 7, 2022
Pokeapi wrapper, written in Swift

PokemonKit What is this? PokemonKit is a swift wrapper for Pokeapi. PokemonKit use Alamofire and PromiseKit for async web requests handling. Usage imp

Continuous Learning 105 Nov 16, 2022
A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

Matt Donnelly 2.4k Dec 30, 2022
A Jamf Classic communication framework written in Swift

JamfKit JamfKit is an iOS / macOS / tvOS framework to communicate with the JSS API offered by any Jamf host. Summary Features Installation Carthage Co

Damien R. 40 Mar 31, 2022
Questrade API written in Swift.

QuestradeAPI Getting Started The QuestAPI is made up of two main concepts: ResponseProviders API ResponseProviders The job of the provider is to retur

Eli Slade 2 Mar 15, 2022
The Easiest and Simplest iOS library for Twitter and Facebook. Just Drop in and Use!

EasySocial iOS Library for Twitter and Facebook This library allows your apps to use Twitter and Facebook with minimal understanding of the relevant S

pj 124 Nov 17, 2022
Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging.

Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging. Included services are Dropbox, Google Drive, OneDrive, OneDrive for Business, Box, Egnyte, PayPal, Stripe, Google Places, Foursquare, Yelp, YouTube, Vimeo, Twitch, Facebook Messenger, Telegram, Line, Viber, Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Mailjet, Sendgrid, Twilio, Nexmo, Twizo.

CloudRail 195 Nov 29, 2021
iTunes Connect Library inspired by FastLane

Mothership iTunes Connect Library inspired by FastLane I wrote MotherShip for two reasons. love FastLane, but I am not proficient in Ruby. I wanted to

thecb4 74 Nov 3, 2022
A Swift library for the Forecast.io Dark Sky API

Requirements To use ForecastIO, all you need is an API key for the Dark Sky API. ForecastIO supports iOS (≥9.0), macOS (≥10.10), watchOS (≥2.0), and t

Satyam Ghodasara 163 Jul 26, 2022
This repository is for the new ARGear SDK library for the iOS platform

This repository is for the new ARGear SDK library for the iOS platform. The library is not official yet. The library will be updated frequently by applying user feedback. When the APIs are fixed, the official library will be released.

ARGear 2 Apr 5, 2022