mzeeshanid / MZDownloadManager

This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
BSD 3-Clause "New" or "Revised" License
1.12k stars 238 forks source link

Issue on MZDownloadManager.swift isValidResumeData line 156 #85

Closed hkarmoush closed 2 years ago

hkarmoush commented 5 years ago

The reason for the crash or the scenario that this crash is caused is not clear for now. I will be attaching the crash report from Firebase Crashlytics and let's hope someone faced the same issue and may provide either a scenario for this crash to be triggered so I can debug it and the have a solution for it.

screen shot 2019-03-05 at 14 15 28
Harshad290194 commented 5 years ago

@7snalbar also repeat same issue for resume downloading

hkarmoush commented 5 years ago

@Harshad290194 Did you understand what caused it? Or do you have any more information on how to regenerate the issue? If yes then It'd help me solve it. Since @mzeeshanid doesn't care to reply on the issues that his work caused.

Thanks

Harshad290194 commented 5 years ago

@7snalbar When we pause download task and resume again then crash issue is generated.. not for every time but some time generate... issue is generated in latest pod file... not old pod file...

Harshad290194 commented 5 years ago

@7snalbar When we start downloading and kill app when already downloading inProgress.. and resume download then crash is generated... for resume data...

CokePokes commented 5 years ago

Try this:

fileprivate func isValidResumeData(_ resumeData: Data?) -> Bool {

        guard resumeData != nil || resumeData?.count > 0 else {
            return false
        }

        do {
            var resumeDictionary : AnyObject!
            resumeDictionary = try PropertyListSerialization.propertyList(from: resumeData!, options: PropertyListSerialization.MutabilityOptions(), format: nil) as AnyObject?
            var localFilePath = (resumeDictionary?["NSURLSessionResumeInfoLocalPath"] as? String)

            if localFilePath == nil || localFilePath?.count < 1 {
                localFilePath = (NSTemporaryDirectory() as String) + (resumeDictionary["NSURLSessionResumeInfoTempFileName"] as! String)
            }

            let fileManager : FileManager! = FileManager.default
            debugPrint("resume data file exists: \(fileManager.fileExists(atPath: localFilePath! as String))")
            return fileManager.fileExists(atPath: localFilePath! as String)
        } catch let error as NSError {
            debugPrint("resume data is nil: \(error)")
            return false
        }
    }

Although, when resuming the download after quitting the app, the download fails and causes new downloads to fail as well. Reply if you find a fix to this issue.

shubhankarbhavsar commented 5 years ago

Hi All,

I'm also facing this issue. Anyone working on solutions?

mml237 commented 5 years ago

Hello everyone! I'am also facing this issue. When I pause the task, relaunch the app and click the Downloading button. The crash occur. image image image image Anyone can help me? Thanks a lot!

mzeeshanid commented 5 years ago

In upcoming version i will remove this function as it is no longer needed.

dlpigpen commented 5 years ago

Try this:

fileprivate func isValidResumeData(_ resumeData: Data?) -> Bool {

        guard resumeData != nil || resumeData?.count > 0 else {
            return false
        }

        do {
            var resumeDictionary : AnyObject!
            resumeDictionary = try PropertyListSerialization.propertyList(from: resumeData!, options: PropertyListSerialization.MutabilityOptions(), format: nil) as AnyObject?
            var localFilePath = (resumeDictionary?["NSURLSessionResumeInfoLocalPath"] as? String)

            if localFilePath == nil || localFilePath?.count < 1 {
                localFilePath = (NSTemporaryDirectory() as String) + (resumeDictionary["NSURLSessionResumeInfoTempFileName"] as! String)
            }

            let fileManager : FileManager! = FileManager.default
            debugPrint("resume data file exists: \(fileManager.fileExists(atPath: localFilePath! as String))")
            return fileManager.fileExists(atPath: localFilePath! as String)
        } catch let error as NSError {
            debugPrint("resume data is nil: \(error)")
            return false
        }
    }

Although, when resuming the download after quitting the app, the download fails and causes new downloads to fail as well. Reply if you find a fix to this issue.

Someone can let me know. Does it work?

Harshad290194 commented 5 years ago

We already solve this issue.. Thank you so much for your reply

On Mon, 19 Aug 2019 at 1:01 PM, Duc Nguyen notifications@github.com wrote:

Try this:

fileprivate func isValidResumeData(_ resumeData: Data?) -> Bool {

    guard resumeData != nil || resumeData?.count > 0 else {
        return false
    }

    do {
        var resumeDictionary : AnyObject!
        resumeDictionary = try PropertyListSerialization.propertyList(from: resumeData!, options: PropertyListSerialization.MutabilityOptions(), format: nil) as AnyObject?
        var localFilePath = (resumeDictionary?["NSURLSessionResumeInfoLocalPath"] as? String)

        if localFilePath == nil || localFilePath?.count < 1 {
            localFilePath = (NSTemporaryDirectory() as String) + (resumeDictionary["NSURLSessionResumeInfoTempFileName"] as! String)
        }

        let fileManager : FileManager! = FileManager.default
        debugPrint("resume data file exists: \(fileManager.fileExists(atPath: localFilePath! as String))")
        return fileManager.fileExists(atPath: localFilePath! as String)
    } catch let error as NSError {
        debugPrint("resume data is nil: \(error)")
        return false
    }
}

Although, when resuming the download after quitting the app, the download fails and causes new downloads to fail as well. Reply if you find a fix to this issue.

Someone can let me know. Does it work?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mzeeshanid/MZDownloadManager/issues/85?email_source=notifications&email_token=AEDZ4E4OAFPKCWNBJ4PG54LQFJD47A5CNFSM4G3ZPN62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4R66SY#issuecomment-522448715, or mute the thread https://github.com/notifications/unsubscribe-auth/AEDZ4E77QWOQRXVJVG2VX23QFJD47ANCNFSM4G3ZPN6Q .

dlpigpen commented 5 years ago

@Harshad290194 Thank a lot.