Cloud Drive(GoogleDrive/Dropbox/BaiduPan/OneDrive/pCloud) File Management

Overview

CloudServiceKit

Easy to integrate cloud service using Oauth2. Supported platforms:

  • AliyunDrive
  • BaiduPan
  • Box
  • Dropbox
  • Google Drive
  • OneDrive
  • pCloud

Requirements

  • Swift 5.0 +
  • Xcode 12 +
  • iOS 13.0 +

Installation

CocoaPods

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

pod 'CloudServiceKit'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding CloudServiceKit as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/alexiscn/CloudServiceKit.git", from: "1.0.0")
]

Quick Start

You can explore CloudServiceKit by running example. But first you should configure app information that cloud drive services provides, you can fulfill information in CloudConfiguration.swift.

extension CloudConfiguration {
    
    static var baidu: CloudConfiguration? {
        // fulfill your baidu app info
        return nil
    }
    
    static var box: CloudConfiguration? {
        return nil
    }
    
    static var dropbox: CloudConfiguration? {
        return nil
    }
    
    static var googleDrive: CloudConfiguration? {
        return nil
    }
    
    static var oneDrive: CloudConfiguration? {
        return nil
    }
    
    static var pCloud: CloudConfiguration? {
        return nil
    }
}

Get Started

Using CloudServiceKit should follow following steps:

Assuming that you have already registered app and got appId, appSecret and redirectUrl.

1. Create a connector

Create a connector of the cloud service, pass the necessary parameters:

let connector = DropboxConnector(appId: "your_app_id", appSecret: "your_app_secret", callbackUrl: "your_app_redirect_url")

You should keep a strong reference to the connector.

2. Handle the openURL

Since CloudServiceKit depends on OAuthSwift. You app should handle openURL. Assuming your redirectUrl is like filebox_oauth://oauth-callback.

  • On iOS implement UIApplicationDelegate method
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey  : Any] = [:]) -> Bool {
  if url.host == "oauth-callback" {
    OAuthSwift.handle(url: url)
  }
  return true
}
  • On iOS 13, UIKit will notify UISceneDelegate instead of UIApplicationDelegate. Implement UISceneDelegate method
import OAuthSwift

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    // ...

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set
   ) {
        
        
   guard 
   let url 
   = URLContexts.
   first
   ?.
   url 
   else {
            
   return
        }
        
   if url.
   host 
   == 
   "oauth-callback" {
            OAuthSwift.
   handle(
   url: url)
        }    
    }
  

3. Connect to service

connector.connect(viewController: self) { result in
    switch result {
    case .success(let token):
        let credential = URLCredential(user: "user", password: token.credential.oauthToken, persistence: .permanent)
        // You can save token for next use.
        let provider = DropboxServiceProvider(credential: credential)
        let vc = DriveBrowserViewController(provider: provider, directory: provider.rootItem)
        self.navigationController?.pushViewController(vc, animated: true)
    case .failure(let error):
        print(error)
    }
}

CloudServiceProvider

CloudServiceProvider is a protocol offers methods to operate with cloud services.

    /// Get attributes of cloud item.
    /// - Parameters:
    ///   - item: The target item.
    ///   - completion: Completion callback.
    func attributesOfItem(_ item: CloudItem, completion: @escaping (Result
   Error>) 
   -> 
   Void)
    
    
   /// Load the contents at directory.

       
   /// - Parameters:

       
   ///   - directory: The target directory to load.

       
   ///   - completion: Completion callback.

       
   func 
   contentsOfDirectory(
   _ 
   directory: CloudItem, 
   completion: 
   @escaping (Result<[CloudItem], 
   Error>) 
   -> 
   Void)
    
    
   /// Copy item to directory

       
   /// - Parameters:

       
   ///   - item: The item to be copied.

       
   ///   - directory: The destination directory.

       
   ///   - completion: Completion callback.

       
   func 
   copyItem(
   _ 
   item: CloudItem, 
   to 
   directory: CloudItem, 
   completion: 
   @escaping CloudCompletionHandler)
    
    
   /// Create folder at directory.

       
   /// - Parameters:

       
   ///   - folderName: The folder to be created.

       
   ///   - directory: The destination directory.

       
   ///   - completion: Completion callback. The completion block will called in main-thread.

       
   func 
   createFolder(
   _ 
   folderName: 
   String, 
   at 
   directory: CloudItem, 
   completion: 
   @escaping CloudCompletionHandler)
    
    
   /// Get the space usage information for the current user's account.

       
   /// - Parameter completion: Completion block.

       
   func 
   getCloudSpaceInformation(
   completion: 
   @escaping (Result
   
    Error>) 
    -> 
    Void)
    
    
    /// Get information about the current user's account.

        
    /// - Parameter completion: Completion block.

        
    func 
    getCurrentUserInfo(
    completion: 
    @escaping (Result
    
     Error>) 
     -> 
     Void)
    
    
     /// Move item to target directory.

         
     /// - Parameters:

         
     ///   - item: The item to be moved.

         
     ///   - directory: The target directory.

         
     ///   - completion: Completion block.

         
     func 
     moveItem(
     _ 
     item: CloudItem, 
     to 
     directory: CloudItem, 
     completion: 
     @escaping CloudCompletionHandler)
    
    
     /// Remove cloud file/folder item.

         
     /// - Parameters:

         
     ///   - item: The item to be removed.

         
     ///   - completion: Completion block.

         
     func 
     removeItem(
     _ 
     item: CloudItem, 
     completion: 
     @escaping CloudCompletionHandler)
    
    
     /// Rename cloud file/folder to a new name.

         
     /// - Parameters:

         
     ///   - item: The item to be renamed.

         
     ///   - newName: The new name.

         
     ///   - completion: Completion block.

         
     func 
     renameItem(
     _ 
     item: CloudItem, 
     newName: 
     String, 
     completion: 
     @escaping CloudCompletionHandler)
    
    
     /// Search files with provided keyword.

         
     /// - Parameters:

         
     ///   - keyword: The keyword.

         
     ///   - completion: Completion block.

         
     func 
     searchFiles(
     keyword: 
     String, 
     completion: 
     @escaping (Result<[CloudItem], 
     Error>) 
     -> 
     Void)
    
    
     /// Upload file data to target directory.

         
     /// - Parameters:

         
     ///   - data: The data to be uploaded.

         
     ///   - filename: The filename to be created.

         
     ///   - directory: The target directory.

         
     ///   - progressHandler: The upload progress reporter. Called in main thread.

         
     ///   - completion: Completion block.

         
     func 
     uploadData(
     _ 
     data: Data, 
     filename: 
     String, 
     to 
     directory: CloudItem, 
     progressHandler: 
     @escaping ((Progress) 
     -> 
     Void), 
     completion: 
     @escaping CloudCompletionHandler)
    
    
     /// Upload file to target directory with local file url.

         
     /// Note: remote file url is not supported.

         
     /// - Parameters:

         
     ///   - fileURL: The local file url.

         
     ///   - directory: The target directory.

         
     ///   - progressHandler: The upload progress reporter. Called in main thread.

         
     ///   - completion: Completion block.

         
     func 
     uploadFile(
     _ 
     fileURL: URL, 
     to 
     directory: CloudItem, 
     progressHandler: 
     @escaping ((Progress) 
     -> 
     Void), 
     completion: 
     @escaping CloudCompletionHandler)
    
   
  

Connector

CloudServiceKit provides a default connector for each cloud service that CloudServiceKit supported. It handles OAuth2.0 flow. What you need to do is provide the app information that you applied from cloud service console.

let connector = DropboxConnector(appId: "{you_app_id}", 
                                 appSecret: "{your_app_secret}", 
                                 callbackUrl: "{your_redirect_url}")

Here is the connector list that CloudServiceKit supported.

  • BaiduPanConnector
  • BoxConnector
  • DropboxConnector
  • GoogleDriveConnector
  • OneDriveConnector
  • PCloudConnector

You can also create your own connector.

Advance Usage

You can create extensions to add more functions to existing providers. Following example shows show to export file at Dropbox.

extension DropboxServiceProvider {
    
    func export(file: CloudItem, completion: @escaping CloudCompletionHandler) {
        let url = apiURL.appendingPathComponents("files/export")
        let dict = ["path": file.path]
        var headers: [String: String] = [:]
        headers["Dropbox-API-Arg"] = dropboxAPIArg(from: dict)
        post(url: url, headers: headers) { response in
            switch response.result {
            case .success(let result):
                print(result)
            case .failure(let error):
                print(error)
            }
        }
    }
}
You might also like...
A quick and simple way to authenticate a Dropbox user in your iPhone or iPad app.
A quick and simple way to authenticate a Dropbox user in your iPhone or iPad app.

DropboxSimpleOAuth A quick and simple way to authenticate a Dropbox user in your iPhone or iPad app. Adding DropboxSimpleOAuth to your project CocoaPo

Simple camera application for iOS that uploads pictures to WebDAV server or Dropbox quickly. Available on the AppStore.
Simple camera application for iOS that uploads pictures to WebDAV server or Dropbox quickly. Available on the AppStore.

Upupu Simple camera application for iOS that uploads pictures to WebDAV server or Dropbox quickly. Also available on the AppStore. Features Easy and f

A Dropbox v2 client library written in Objective-C

TJDropbox TJDropbox is a Dropbox v2 client library written in Objective-C. When Dropbox originally announced their v2 API they included only a Swift c

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

FileKit is a Swift framework that allows for simple and expressive file management.
FileKit is a Swift framework that allows for simple and expressive file management.

FileKit is a Swift framework that allows for simple and expressive file management.

File management and path analysis for Swift
File management and path analysis for Swift

Pathos offers cross-platform virtual file system APIs for Swift. Pathos is implement from ground-up with on each OS's native API. It has zero dependen

ips2crash is a macOS command line too to convert a .ips file to a legacy .crash log file.

Synopsis ips2crash is a macOS command line too to convert a .ips file to a legacy .crash log file. Motivation It should be possible to read .ips file

Edit a file, create a new file, and clone from Bitbucket in under 2 minutes

Edit a file, create a new file, and clone from Bitbucket in under 2 minutes When you're done, you can delete the content in this README and update the

LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.
LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.

LinkedLog Xcode Plugin LinkedLog is a Xcode plugin that includes a Xcode PCH file template that adds the macros LLog and LLogF. The LLog macro will wo

An Adobe .ase (Adobe Swatch Exchange File), .aco (Photoshop swatch file) reader/writer package for Swift (macOS, iOS, tvOS, macCatalyst)

ColorPaletteCodable A palette reader/editor/writer package for iOS, macOS, watchOS and tvOS, supporting the following formats Adobe Swatch Exchange (.

Securely synchronize any CareKit 2.1+ based app to a Parse Server Cloud. Compatible with parse-hipaa.
Securely synchronize any CareKit 2.1+ based app to a Parse Server Cloud. Compatible with parse-hipaa.

ParseCareKit Use at your own risk. There is no promise that this is HIPAA compliant and we are not responsible for any mishandling of your data This f

Flow layout / tag cloud / collection view in SwiftUI.
Flow layout / tag cloud / collection view in SwiftUI.

SwiftUIFlowLayout A Flow Layout is a container that orders its views sequentially, breaking into a new "line" according to the available width of the

Screen translator for macOS with Apple Vision API and IBM Watson, Google Cloud Translator
Screen translator for macOS with Apple Vision API and IBM Watson, Google Cloud Translator

Swifty-OCR-Translator Screen translator for macOS with Apple Vision API and IBM Watson, Google Cloud Translator Usage Select Translator Fill in the AP

🌟🌟🌟🌟🌟 Falcon Messenger is a Fast and Beautiful cloud-based messaging app. With iOS and IPadOS Support. Available on the App Store.
🌟🌟🌟🌟🌟 Falcon Messenger is a Fast and Beautiful cloud-based messaging app. With iOS and IPadOS Support. Available on the App Store.

Open the FalconMessenger.xcworkspace in Xcode. Change the Bundle Identifier to match your domain. Go to Firebase and create new project. Select "Add F

Integrate third party libraries by using Cocoapods and Swift Package Manager, store data in the cloud using Firebase Firestore.
Integrate third party libraries by using Cocoapods and Swift Package Manager, store data in the cloud using Firebase Firestore.

Integrate third party libraries by using Cocoapods and Swift Package Manager, store data in the cloud using Firebase Firestore. Exercising query and s

A Neumorphism UI NetEase Cloud Music With SwiftUI
A Neumorphism UI NetEase Cloud Music With SwiftUI

A Neumorphism UI NetEase Cloud Music With SwiftUI

Evernote Cloud SDK for iOS
Evernote Cloud SDK for iOS

Evernote Cloud SDK 3.0 for iOS This is the official Evernote SDK for iOS. To get started, follow the instructions bellow. Additional information can b

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.

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.

This page contains an iOS Application that uses Modelplace.AI Cloud API

Modelplace iOS App This page contains an iOS Application that uses Modelplace.AI

Owner
an indie developer
null
Evernote Cloud SDK for iOS

Evernote Cloud SDK 3.0 for iOS This is the official Evernote SDK for iOS. To get started, follow the instructions bellow. Additional information can b

Evernote 256 Oct 6, 2022
A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud written in Swift.

Elastic Path Commerce Cloud iOS Swift SDK A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elasti

Moltin 36 Aug 1, 2022
An open-source task management app for daily general operations

Taskaholic An open-source task management app for daily general operations, sepa

Aiden 1 Sep 19, 2022
SharedImages Screen grabs Main Features Private & self-owned social media Users store their images in their own cloud storage (Dropbox or Google Drive

SharedImages Screen grabs Main Features Private & self-owned social media Users store their images in their own cloud storage (Dropbox or Google Drive

Christopher Prince 12 Feb 10, 2022
FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift

This Swift library provide a swifty way to deal with local and remote files and directories in a unified way. This library provides implementaion of W

Amir Abbas Mousavian 890 Jan 6, 2023
Cozy Drive Web App for Cozy Cloud

Cozy Drive What's Cozy? Cozy is a platform that brings all your web services in the same private space. With it, your webapps and your devices can sha

Cozy.io 138 Dec 14, 2022
OneDrive SDK for iOS

Get started with the OneDrive SDK for iOS Integrate the OneDrive API into your iOS app! 1. Installation Install via Cocoapods Install Cocoapods - Foll

OneDrive 101 Dec 19, 2022
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.

Capacitor Community 32 Dec 21, 2022
iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.

iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.While the cost of storage seems expensive in comparison to other online storage services, its advantage is that it works natively across all your devices.

MindInventory 12 Jul 29, 2022
SwiftCloudDrive - An easy to use Swift wrapper around iCloud Drive.

SwiftCloudDrive Author: Drew McCormack (@drewmccormack) An easy to use Swift wrapper around iCloud Drive. SwiftCloudDrive handles complexities like fi

Drew McCormack 11 Dec 21, 2022