Code Monkey home page Code Monkey logo

tinydropbox's Introduction

It was archived. Please write to me at [email protected] in case any issues occur.

TinyDropbox

CI Status Version License Platform

Brief

Easy to use dropbox sync for swift coders [wrapper on TBDropboxKit]

Please use issues to propose additional functions to be implemented!

Versions

1.0.1 add state property

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

To receive server files changes set watchdogEnabled to true

patch info.plist file of the target

```

LSApplicationQueriesSchemes dbapi-8-emm dbapi-2 CFBundleURLTypes CFBundleURLSchemes db-f73chv4vrf1uv40 CFBundleURLName ```

initialize in app delegate

add properties to AppDelegate

```
let dropboxStateChangedNotification = "dropboxStateChangedNotification"
let dropboxStateNotificationKey = "dropboxStateNotificationKey"
let dropbox = TinyDropbox.shared```

add AppDelegate as dropbox delegate

``` class AppDelegate: UIResponder, UIApplicationDelegate, TinyDropboxDelegate {```

```
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    dropbox.delegate = self
    // Override point for customization after application launch.
    return true
}```

```
// MARK: TinyDropboxDelegate

func dropbox(_ dropbox: TinyDropbox, didChangeStateTo state: TinyDropboxState) {
    let userInfo = [dropboxStateNotificationKey: state]
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: dropboxStateChangedNotification), object: self, userInfo: userInfo)
}

func dropbox(_ dropbox: TinyDropbox, didReceiveIncomingChanges changes: Array<DropChange>) {

}
```

handle dropbox auth redirect in an AppDelegete

```
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    let result = dropbox.handleAuthorisationRedirectURL(url)
    return result
}
```

subscribe to notifications

```
 private func subscribeToNotifications () {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(ListDropboxViewController.dropboxDidCahngeState(notification:)),
                                           name: NSNotification.Name(rawValue: appDelegate.dropboxStateChangedNotification),
                                           object: appDelegate)
}

func dropboxDidCahngeState (notification: NSNotification) {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let state = notification.userInfo?[appDelegate.dropboxStateNotificationKey];
    
    if let state = state as? TinyDropboxState{
        if state == .connected
        || state == .reconnected {
            download(using: appDelegate.dropbox)
       }
    }
}```

list books folder and download first one if no local copy present

```
private func download(using dropbox: TinyDropbox) {
dropbox.append(path: "/books")
    dropbox.listDirectory { (list: DropboxFilesList, error :DropboxError?) in
        guard list != nil, list!.count > 1 else {
            return
        }
        
        var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
        path.append("/book.pdf")
        let url = URL.init(fileURLWithPath: path)
        let richable = try? url.checkResourceIsReachable()
        
        guard richable == nil || richable == false else {
            self.open(fileAt: url)
            return
        }
        
        print(url);
        
        dropbox.download(atPath: list![0], to: url, completion: { [weak self]  (error: DropboxError?) in
            if let error = error {
                print(error)
            } else {
                self?.open(fileAt: url)
            }
        })
    }
}```

Requirements

Installation

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

pod "TinyDropbox"

Author

truebucha, [email protected]

License

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

tinydropbox's People

Contributors

kanstantsin-bucha avatar

Stargazers

Carabineiro avatar

Watchers

Carabineiro avatar  avatar

Forkers

carabina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.