Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSData gives me an error in version 9.0

Given below is my function written in swift this code works fine in 10.0 version of iPhone but gives an error in 9.0 saying

CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme Failed to load: The file “Recording2017-03-06_11.08.53000.mp3” couldn’t be opened.

partFileURL will be having

/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3

This is my below function-:

//function
func putPartUplaod(partFileURL:URL , partFileNumber:Int)
{
        var partfileData:Data?
        var md5hash:Any?
        var sha256hash:Any?
        //  var error: NSError?   
        let uri:URL = NSURL(fileURLWithPath: partFileURL.absoluteString) as URL

        //Get MD5 Digest
        do{
            print(partFileURL)
            partfileData = try NSData(contentsOf: uri, options: NSData.ReadingOptions.dataReadingMapped) as Data    
            print("hello" , partfileData);
            md5hash = partfileData?.md5().base64EncodedString()  
        }catch let error as NSError {
            print("Failed to load: \(error.localizedDescription)")
        }
}
like image 974
nikhil Avatar asked Dec 20 '25 22:12

nikhil


2 Answers

You can use something like NSData *data = [[NSFileManager defaultManager] contentsAtPath:path]; The string that you're passing in is not a valid URL, it's just a file path. For making it URL, you would need to add the scheme which would be file://.

like image 191
manman Avatar answered Dec 22 '25 11:12

manman


/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3is a file path and not a url. A url has a scheme (or protocol). See your error message. Create your url with

URL(fileURLWithPath:"/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3")
like image 33
clemens Avatar answered Dec 22 '25 11:12

clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!