2017-03-06 67 views
3

下面給出的是我的函數寫在SWIFT這個代碼在10.0版iPhone的罰款,但在9.0 的NSData讓我在版本錯誤9.0

CFURLCopyResourcePropertyForKey失敗,因爲它傳遞了一個給出了一個錯誤URL 沒有方案無法加載:文件 「Recording2017-03-06_11.08.53000.mp3」無法打開。

partFileURL將具有

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

這是我下面的函數 - :

//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)") 
     } 
} 
+0

你傳遞的是什麼partFileURL值? – manman

+0

Im通過: **/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3 ** – nikhil

+0

什麼是目的從URL('partFileURL')創建URL('uri')?順便說一句:不要使用'NSData','NSURL'在Swift 3 – vadian

回答

2

您的網址,您可以使用類似NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];您傳遞的是不是一個有效的URL字符串,它只是一個文件路徑。爲了製作URL,您需要添加file://的方案。

+1

-Tried作品 IPhone 7(OS 10.2.1), IPhone 6S(OS 10.2.1), iPhone 6(OS 10.2.1), 的iPhone 5S(OS 10.2.1 )但在 iPhone 5(OS 9.3.5) - 不工作 – nikhil

+1

是因爲版本....? – nikhil

+0

@nikhil 9.3.5的錯誤是什麼?你確定文件路徑存在嗎? – manman

2

/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3是一個文件路徑,而不是一個網址。一個url有一個方案(或協議)。看到你的錯誤信息。創建

URL(fileURLWithPath:"/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3") 
+0

- 已完成的作品在 IPhone 7(OS 10.2.1) IPhone 6S(OS 10.2.1) iPhone 6(OS 10.2.1) 的iPhone 5S(OS 10.2.1),但在 IPhone 5(OS 9.3.5 ) - 沒有工作 – nikhil

+0

你如何創建網址,什麼是確切的錯誤信息?避免這樣的消息沒有細節。 – clemens

+0

我在問題本身中給出了錯誤消息 – nikhil