繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM