[英]Dropbox SDK for iOS works on simulator, not on actual device
我正在從事一個項目,該項目涉及一個iOS應用程序,該應用程序通過Dropbox同步數據與另一台設備進行通信。
當我在iPhone Simulator上運行該軟件(它可以同步,上傳,下載而沒有問題)時,它工作得很好,但是當我將其加載到實際設備上時,會出現加載/保存錯誤。
模擬器和iPhone上的應用均已成功鏈接到我的Dropbox帳戶。
我嘗試執行加載請求時出現一些錯誤:
2015-05-18 23:27:19.385 [2218:923269] [ERROR] DBRequest#connectionDidFinishLoading: error moving temp file to desired location: The operation couldn’t be completed. (Cocoa error 516.)
2015-05-18 23:27:19.387 [2218:923269] [WARNING] DropboxSDK: error making request to /1/files/dropbox/Projekt 2 (1)/Program/Units.txt - (516) Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" UserInfo=0x174077700 {path=/Projekt 2 (1)/Program/Units.txt, destinationPath=/...}
我的應用中與保管箱相關的代碼示例:
在AppDelegate.swift中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let session = DBSession(appKey: "myAppKey", appSecret: "myAppSecret", root: kDBRootDropbox)
DBSession.setSharedSession(session)
...
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if DBSession.sharedSession().handleOpenURL(url) {
if DBSession.sharedSession().isLinked() {
// Linking was successfull.
}
return true
}
return false
}
在ViewControllerCausingErrors.swift中:
class ViewControllerCausingErrors: DBRestClientDelegate {
var dbClient = DBRestClient()
override func viewDidLoad() {
super.viewDidLoad()
self.dbClient = DBRestClient(session: DBSession.sharedSession())
self.dbClient.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated: animated)
if !DBSession.sharedSession().isLinked() {
DBSession.sharedSession().linkFromController(self)
}
}
}
我用於下載文件的代碼塊,在VC中的其他位置
if let localPath = NSBundle.mainBundle().pathForResource("Units", ofType: "txt") {
// Download file from Dropbox to local path.
let dropboxPath = Constants.Dropbox.Download.UnitFilePath
self.dbClient.loadFile(dropboxPath, intoPath: localPath)
}
任何幫助是極大的贊賞。
根據iOS文檔 ,錯誤代碼516為:
NSFileWriteFileExistsError = 516,
聽起來設備上提供的localPath
上有一個文件(錯誤中稱為destinationPath
),但模擬器上卻沒有,導致loadFile
無法從下載中寫入文件。
我認為問題出在NSBundle.mainBundle()。pathForResource(“ Units”,ofType:“ txt”)中。 NSBundle用於模擬器,但不用於實際設備。 您只需將Units.txt放在loadFile函數中
self.dbClient.loadFile(dropboxPath,intoPath:“ Units.txt”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.