我正在开展一个项目,涉及iOS应用程序通过Dropbox同步数据与其他设备进行通信。
当我在iPhone模拟器上运行软件时它完全正常(它同步,上传,下载没有问题),但是当我将它加载到我的实际设备上时,我得到加载/保存错误。
模拟器和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=/...}
我的应用中与Dropbox相关的代码示例:
在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)
}
非常感谢任何帮助。
答案 0 :(得分:1)
根据iOS documentation,错误代码516是:
NSFileWriteFileExistsError = 516,
听起来设备上提供的localPath
上有一个文件(错误中称为destinationPath
),但模拟器上没有,导致loadFile
不能能够从下载中写入文件。
答案 1 :(得分:0)
我认为问题出在NSBundle.mainBundle()。pathForResource(" Units",ofType:" txt")。 NSBundle用于模拟器,但不用于实际设备。您只需将Units.txt放在loadFile函数
中self.dbClient.loadFile(dropboxPath,intoPath:" Units.txt")