Latest 1.0.1
Homepage https://github.com/truebucha/TinyDropbox
License MIT
Platforms ios 9.0
Dependencies TBDropboxKit, BuchaSwift
Frameworks Foundation
Authors

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

<array>
    <string>dbapi-8-emm</string>
    <string>dbapi-2</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>db-f73chv4vrf1uv40</string>
        </array>
        <key>CFBundleURLName</key>
        <string></string>
    </dict>
</array>
```

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.

Latest podspec

{
    "name": "TinyDropbox",
    "version": "1.0.1",
    "summary": "Easy to use dropbox sync for swift coders [wrapper on TBDropboxKit]",
    "description": "Easy to use dropbox sync for swift coders [wrapper on TBDropboxKit] Could list files, upload, download andnwatching server changes",
    "homepage": "https://github.com/truebucha/TinyDropbox",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "truebucha": "[email protected]"
    },
    "source": {
        "git": "https://github.com/truebucha/TinyDropbox.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/truebucha",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "TinyDropbox/Classes/**/*.{swift}",
    "frameworks": "Foundation",
    "dependencies": {
        "TBDropboxKit": [
            "~> 1.1"
        ],
        "BuchaSwift": [
            "~> 1.0"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This