l_priebe
l_priebe

Reputation: 794

Dropbox SDK for iOS works on simulator, not on actual device

I am working on a project involving an iOS app communicating with another device by way of syncing data through Dropbox.

It works perfectly fine when I run the software on the iPhone Simulator (it syncs, uploads, downloads without issues), but when I load it onto my actual device, I get load/save errors.

The app on both the simulator and iPhone was successfully linked to my Dropbox account.

Some errors when I try do load requests:

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=/...}

Samples of the dropbox related code in my app:

In 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 
}

In 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)
        }
    }
}

Chunk of code i use to download a file, elsewhere in the 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)
}

Any help is greatly appreciated.

Upvotes: 0

Views: 406

Answers (2)

Mir Ashraf
Mir Ashraf

Reputation: 131

I think problem is in the NSBundle.mainBundle().pathForResource("Units", ofType: "txt"). NSBundle is used in simulator but not in actual device. You just place Units.txt in your loadFile function

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

Upvotes: 0

Greg
Greg

Reputation: 16940

According to the iOS documentation, error code 516 is:

NSFileWriteFileExistsError = 516,

It sounds like there's a file at the supplied localPath on the device (called destinationPath in the error), but not on the simulator, causing loadFile to not be able to write the file from the download.

Upvotes: 1

Related Questions