You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

gcarl's avatar
gcarl
Explorer | Level 4
3 years ago

NSURLErrorDomainCode=-1005 with authorizedClient in iOS-App

Dear community,

 

I developed a cookbook-app for iOS to manage recipes. The app saves the recipe data in a json-file on a Dropbox folder, which can be defined by the user. If photos are linked to a recipe, these are saved separately in jpg-files on the Dropbox too. The recipe data are loaded when the app is started or when recipes are edited. The photos are loaded when the recipe, to which the photos are linked, is selected to be displayed.

 

As described in SwiftyDropbox manual, I do the authorization with the following workflow

 

 

func connectDropbox(withRequest request: Dropboxrequest) {
        dropboxrequest = request
        let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["files.content.write", "files.content.read", "account_info.read"], includeGrantedScopes: true)
            DropboxClientsManager.authorizeFromControllerV2(
                UIApplication.shared,
                controller: self,
                loadingStatusDelegate: nil,
                openURL: { (url: URL) -> Void in UIApplication.shared.open(url, options: [:], completionHandler: nil) },
                scopeRequest: scopeRequest
            )
    }

 

 

and handle the redirect as described. All works fine so far. Unfortunately, the connection to the dropbox seems to be not stable. 

 

Before reading or writing data, I check, if an authorized client exists as follows:

 

 

 

if let client = DropboxClientsManager.authorizedClient /*getClient()*/ {
    dropboxrequest = .checkFile
    client.files.download(path: aktuellesKochbuch.credentials.urlFile)
        .response { response, error in
            if let response = response {
                let _ = response.0
                let fileContents = response.1
                self.finishInit(withData: fileContents, withError: false)
            } else if let error = error {
                switch error as CallError {
                case .routeError:
                    self.finishInit(withData: Data(), withError: true)
                default:
                    showAlert(withTitle: String(format: NSLocalString("E036 Dropbox access error: \n%@", comment: "E036 Fehler Dropboxzugriff"),error.description), withMessage: "Please check Dropbox status")
                    return
                }
            }
        }
}

 

 

especially, if the app is in use for a longer time, it leads to the following Callerror:

 

 

E036 Fehler Dropboxzugriff: sessionTaskFailed (error: Error
Domain=NSURLErrorDomain
Code=-1005 "Die
Netzwerkverbindung wurde
unterbrochen."
Userinfo=<_kCFStreamErrorCodeKey=-4,
NSUnderlyingError=0x282391cb0 {Error
Domain=kCFErrorDomainCFNetwork Code=-1005 " (null)" UserInfo=<NSErrorPeerAddressKev=<CFData0x280ed5040[Ox212cdc580]>{length = 16,capacity = 16, bytes =
0x100201bba27d420e0000000000000000}, 
_kCFStreamErrorCodeKey=-4
_kCFStreamErrorDomainKey=4}},
NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask
...

 

 

One user, who is reporting many of these errors, has stored the data on a shared folder with another user in Dropbox.

Does anyone have an idea, what the reason for this instability could be?

 

Thanks for your support.

gcarl

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    That error is being reported by the iOS network client and that "-1005" error code in particular indicates that the network connection was lost.

     

    Does this happen for all users all the time, or only some users/some of the time?

     

    If it only happens sometimes, it may indicate that the network connection was lost for some reason; some of the following may be possible causes:

    • if the network connection is lost, such as due to losing WiFi or cellular reception
    • if the network connection switches between different interfaces, such as WiFi versus cellular
    • if the app is quit during the connection

    Those aren't conditions you can control of course, so you may want to add some automatic retrying to handle those.

     

    If this isn't reproducible for all users/devices, it may be specific to the particular network connections of the affected users/devices. In that case, is there anything that may be interfering with HTTPS connections to api-content.dropbox.com on those network connections? For example, firewalls, proxies, VPNs, etc. may be interfering.