适用于iOS的Dropbox SDK适用于模拟器,而不适用于实际设备

问题描述 投票:0回答:2

我正在开发一个涉及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)
}

任何帮助是极大的赞赏。

ios swift dropbox dropbox-api
2个回答
1
投票

根据iOS documentation,错误代码516是:

NSFileWriteFileExistsError = 516,

听起来设备上提供的localPath上有一个文件(在错误中称为destinationPath),但在模拟器上没有,导致loadFile无法从下载中写入文件。


0
投票

我认为问题出在NSBundle.mainBundle()。pathForResource(“Units”,ofType:“txt”)中。 NSBundle用于模拟器,但不用于实际设备。您只需将Units.txt放在loadFile函数中即可

self.dbClient.loadFile(dropboxPath,intoPath:“Units.txt”)

© www.soinside.com 2019 - 2024. All rights reserved.