TinyDropbox
简介
针对 Swift 开发者的易于使用 Dropbox 同步 [TBDropboxKit 包装器]
请使用问题来提出要实现的其他功能!
版本
1.0.1 添加状态属性
示例
要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install
要接收服务器文件更改,请将 watchdogEnabled 设置为 true
修复目标项目的info.plist文件
```
LSApplicationQueriesSchemes dbapi-8-emm dbapi-2 CFBundleURLTypes CFBundleURLSchemes db-f73chv4vrf1uv40 CFBundleURLName
在:]中初始化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>) {
}
```
在AppDelegete中处理Dropbox身份验证重定向
```
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let result = dropbox.handleAuthorisationRedirectURL(url)
return result
}
```
订阅通知
```
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)
}
}
}```
列出书籍文件夹,如果本地没有副本,则下载第一个
```
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)
}
})
}
}```
要求
安装
TinyDropbox通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中
pod "TinyDropbox"
作者
truebucha, [email protected]
许可
TinyDropbox目前在MIT许可下可用。更多详情请参阅LICENSE文件。