AnsweredAssumed Answered

generateGeodatabaseWithParameters detecting network error in FetchingResult status

Question asked by hudsonjWSDOT on Oct 14, 2015
Latest reply on Oct 15, 2015 by hudsonjWSDOT

Ok, I have the following code in generateGeodatabaseWithParameters it fires fine and calculates the download speed. The problem I'm having is if a network disruption happens in the AGSResumableTaskJobStatus.FetchingResult status state, I no longer get  status updates, and the call never timeouts. So to the user it just looks like their download has frozen forever. I have a cancel button and I can cancel it but I would rather detect the error and let the user knows that the generate process has failed during that step.

 

if status == AGSResumableTaskJobStatus.FetchingResult {

                               

                                if let userinfo = userInfo  {

                                   

                                    totalBytesDownloaded = userinfo["AGSDownloadProgressTotalBytesDownloaded"] as? NSNumber

                                    totalBytesExpected = userinfo["AGSDownloadProgressTotalBytesExpected"] as? NSNumber

                                   

                                    if totalBytesDownloaded != nil && totalBytesExpected != nil {

                                       

                                        elapsedTime = CACurrentMediaTime() - weakSelf.startTimeMapDl

                                        elapsedSeconds = UInt(elapsedTime)

                                       

                                        if elapsedSeconds > 0 && elapsedSeconds != previousSeconds {

                                           

                                            var bytesPerSecond = UInt(0)

                                           

                                            if previousSeconds == 0 {

                                                dispatch_async(dispatch_get_main_queue()) {

                                                    weakSelf.currentDownloadSpeedHeaderLabel.text = "Current D/L Speed:"

                                                }

                                                bytesPerSecond = totalBytesDownloaded!.unsignedLongValue / elapsedSeconds

                                            }

                                            else {

                                                bytesPerSecond = (totalBytesDownloaded!.unsignedLongValue - previousBytesDownloaded.unsignedLongValue ) / (elapsedSeconds - previousSeconds )

                                            }

                                           

                                            //dl speed bounced between 0 and some other number if checked every second, so spreading it out over 3 seconds

                                            //for a better UI experience.  It still bounces around, but not as much.

                                           

                                            let secondsDifference = elapsedSeconds - previousSeconds

                                           

                                            if secondsDifference > 1 && previousBytesDownloaded.unsignedLongValue != totalBytesDownloaded!.unsignedLongValue {

                                             

                                                dispatch_async(dispatch_get_main_queue()) {

                                                    weakSelf.currentDownloadSpeedLabel.text = "\(NSByteCountFormatter.stringFromByteCount(Int64(bytesPerSecond), countStyle:NSByteCountFormatterCountStyle.File))"

                                                }

                                               

                                                previousBytesDownloaded = totalBytesDownloaded!

                                                previousSeconds = elapsedSeconds

                                               

                                            }

                                        }

                                    }

                                }

                            }

 

For other status states if there is an error I get a error message in the user info, but that does not populate or fire in the fetching result stage.

This at the top of the method call detects network errors for all states, but since FetchingResults never calls back, it can't run.

weakSelf.agsResumableTaskJob = weakSelf.gdbSyncTask?.generateGeodatabaseWithParameters(params,

                        downloadFolderPath: nil,

                        useExisting: false,

                        status: { status, userInfo in

                           

                            if let userinfo = userInfo {

                               

                                if let error = userinfo["statusRequestError"] {

                                   

                                    print("Error: Could not generate geodatabase. Error details:\(error)")

                                    errorOccured = true

                                    weakSelf.agsResumableTaskJob?.cancel()

                                   

                                    if error.localizedDescription == "The Internet connection appears to be offline." {

                                       

                                        dispatch_async(dispatch_get_main_queue()) {

                                           

                                            let alert = UIAlertController(title: "Network Error",

                                                message: "Could not download the map inventory.\r\n\r\nPlease verify you are connected to the Network and try again.",

                                                preferredStyle: UIAlertControllerStyle.Alert)

                                           

                                            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

                                           

                                            weakSelf.presentViewController(alert, animated: true, completion: nil)

                                        }

                                    }

                                    else if error.localizedDescription == "A server with the specified hostname could not be found." {

                                       

                                        dispatch_async(dispatch_get_main_queue()) {

                                           

                                            let alert = UIAlertController(title: "Network Error",

                                                message: "Could not download the map inventory.\r\n\r\nPlease verify you are connected to the Network and try again.",

                                                preferredStyle: UIAlertControllerStyle.Alert)

                                           

                                            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

                                           

                                            weakSelf.presentViewController(alert, animated: true, completion: nil)

                                        }

                                    }

                                    else {

                                        dispatch_async(dispatch_get_main_queue()) {

                                           

                                            let alert = UIAlertController(title: "Error",

                                                message: "Could not download the map inventory.\r\n\r\nPlease verify you are connected to the Network and try again.",

                                                preferredStyle: UIAlertControllerStyle.Alert)

                                           

                                            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

                                           

                                            weakSelf.presentViewController(alert, animated: true, completion: nil)

                                        }

                                    }

                                   

                                }

                            }

 

Using the latest sdk build (10.2.5)

Outcomes