Start a new topic

Found nil values on File downloads on physical devices

Hi,


I am trying to download a file from Kinvey with the below method. It works great in the simulator but suddenly stopped working on our devices. 


It doesn't even print the error messages. I have tried with and without the .network option

The error shows after the fileStore.download call has been made.


Xcode 8.2 and 8.3

Kinvey 3.5.0

Swift 3

iOS 10.2.1

tried on iPhone 6, 7, 6s, 6sPlus



 let fileStore = FileStore.getInstance()

        fileStore.clearCache()

        let file = File()

        file.fileId = "1483c2d6-7c64-47a9-9c98-69b6cf29dcb7" //File ID returned after you upload the file

        fileStore.download(file ,storeType: .network){ (file, url: URL?, error) in

            if let file = file, let url = url {

                //success

                let fileURL = file.downloadURL;

                if let data = NSData(contentsOf: fileURL!) {

                    print("!WALLET_LOG: Downloaded Image successfull &&&&&&&&&&&&&")

                    //self.pirateImage.image = UIImage(data: data as Data)

                    self.nrElementsShowed = self.nrElementsShowed+1;

                    if (self.nrElementsShowed==1) {

                        self.showElements()

                    }

                }

                else {

                    print("===============================> File found but could n)o assign to image")

                }

            } else {

                //fail

                print("===============================> There was an error while downloading the file")

            }

        }


The error I am getting is:

fatal error: unexpectedly found nil while unwrapping an Optional value

2017-04-28 14:27:36.873721 inStore Wallet[471:47645] fatal error: unexpectedly found nil while unwrapping an Optional value



Hello Emilio,


I have investigated this problem and it looks like the problem resides in the Kinvey SDK or the app. I do not see any issues in the Kinvey backend. I have escalated this ticket to the SDK engineering team and I am working with them to investigate further on the SDK side.


I will update this post with additional information as soon as we know more.


Regards,


Billy Gee


MLIBZ-1806

Hello Emilio,


One more questions; does this problem occur for any file that you try to download or just the file that you identified in the above code?


Regards,


Billy Gee

Hello Emilio,


We believe that we have identified the problem as an issue with the application code.


The following code appears to be the root cause of the issue.


let fileURL = file.downloadURL;
if let data = NSData(contentsOf: fileURL!) {
}

 


Please try changing that code to the following code.


if let data = NSData(contentsOf: url) {
}

 


The previous code will try to download the file manually once again which is not necessary since the URL variable already has the file stored locally in the file system. Also, if anything goes wrong such as the internet connection goes down, etc., the ! (exclamation mark) will cause a crash.

Please try making this change, retest and let us know if this resolves your problem or not. If not, we will be happy to continue our investigation.

We look forward to hearing back from you.

Regards,

Billy Gee




1 person likes this

Hi Billy,


Thanks, but changing the code didn't solve the issue. We are still getting the same error on any device.


Please also remember that my previous code works perfectly on the simulator


Best regards,

Hello Emilio,


Please send the new code snippet with the changes that we suggested and I will share that with Engineering as well. I will also ask another iOS engineering to take a look at this during our next shift and see if we can see anything else.


Regards,


Billy Gee

Hi Guys,


Actually the proposed code worked! we just had to clean the dependent files and relaunch xcode 


Best regards,


Hello Emilio,


We are happy to hear it. Please do not hesitate to reach out again if you encounter any other issues or have questions.


Regards,


Billy Gee

Login or Signup to post a comment