[英]iOS DropBox - browse folders and view files - sample code or tutorial?
在我的應用程序中,我希望用戶能夠登錄 DropBox,並瀏覽和查看他或她的文件和文件夾。 這對我來說似乎是一項非常常見的任務,所以我想知道是否有任何教程或示例代碼? 我在谷歌上找不到任何東西。
我相信我可以使用 table view 和來自 dropbox.com 的Core API 教程自己完成,但如果代碼已經在那里,我不想浪費所有時間。
如果您在 Objective c 上查看它,您可以從此鏈接獲取演示項目。 您可以在其中瀏覽根目錄的文件夾,也可以下載文件。
我有同樣的問題。 我花了很長時間才找到答案,真的很不知所措,因為沒有太多關於它的信息。 我這樣做了:對不起,我的英語不是我的母語。
安裝 Dropbox 選擇器https://www.dropbox.com/developers/chooser#ios安裝 SwiftyDropbox
SwiftyDropbox 安裝 Alamofire,我們需要它來下載文件,如果沒有就安裝它
Dropbox Chooser 允許用戶從他們的 Dropbox 帳戶中選擇任何文件並返回所選文件的共享鏈接,因此:
//Ask SwiftyDropbox if the user is logged in
if DropboxClientsManager.authorizedClient != nil{
// Use this from Dropbox chooser to open a view controller that allow the user select the file
//DBChooserLinkTypeDirect <--- it has to be this parameter, there is another one but is useless for our purpose
DBChooser.default().open(for: DBChooserLinkTypeDirect, from: self, completion: { (results) in
//Here starts the completion block of Chooser
if let resultado = results{ //Obtain the results
var d = DBChooserResult() //Create a variable of DBChooserResult type
d = resultado[0] as! DBChooserResult //Get the result. Just one result because the user just can select ONE file (in this version just one, it may be more but I don't know how in this moment
print(d.name)
print(d.link)//The atributte link give us the url to download the file.
//If you paste it in your browser the download starts right away
//Use Alamofire to download the file from the url
Alamofire.request(d.link).responseData { response in
//Get the data from the URL
if let data = response.result.value
{
//Here we have the data to do whatever we want, in my case I show the PDF file in a WebView
print("Data de Alamofire \(response.description)")
self.desplegarUrlEnWebview(datos: data, url: d.link)
}
}
}
})
}else{
//If the user is not logged in we use SwiftyDropbox to log in
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: { (url) in
UIApplication.shared.open(url, options: [:], completionHandler: nil)
})
}
Dropbox API 和 SDK 的所有官方資源都可以在 Dropbox 開發者網站上找到:
https://www.dropbox.com/developers
具體來說,您指的是 iOS 核心 SDK。 您已經提到了教程,但 SDK 下載本身也包含一個工作示例應用程序:
https://www.dropbox.com/developers/core/sdks/ios
該示例不包含您正在尋找的所有功能。
好吧,我已經繼續創建了它。 雖然在嘗試查看 pdf 文件時似乎有問題。 無論如何,這是代碼:
https://github.com/danielbierwirth/DropboxBrowser
有關更多信息,您可以參考 dropbox 的官方開發者網站。
使用 pod 'SwiftyDropbox'。
按照此處的說明配置您的項目: http : //dropbox.github.io/SwiftyDropbox/api-docs/latest/ 。
在您的 Dropbox 應用控制台中,請記住在“權限”選項卡下授予允許您的應用查看和管理文件和文件夾的權限。 如果您對權限進行任何更改,則必須重新生成訪問令牌,並記住在代碼中更改訪問令牌。
由於 dropbox 沒有重定向 url 來在我們登錄后重定向和查看我們的文件和文件夾,因此我們必須創建一個表視圖控制器來加載帶有元數據的文件。 (請記住,您必須從 Dropbox 返回到您的應用才能查看文件)。
如果您想在您的應用程序中使用該文件進行上傳,請使用 tableView 委托方法“didSeelectRowAt”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.