從iPhone傳輸文件到Apple關注後,我得到的錯誤WCSession didReceive文件不可移動的「沒有這樣的文件或目錄」
錯誤域= NSPOSIXErrorDomain代碼= 2「沒有這樣的文件或目錄」
我該怎麼辦錯了嗎?這些代碼片段:
iPhone的ViewController
func makeAction() {
let url = NSURL.fileURL(withPath: fileArray[0].object(at: 2) as! String)
var applicationDict = Dictionary<String, Array<AnyObject>>()
applicationDict["fileArray"] = fileArray
WCSession.default().transferFile(url, metadata: applicationDict)
}
觀看InterfaceController
func session(_ session: WCSession, didReceive file: WCSessionFile) {
DispatchQueue.main.async(execute: {() -> Void in
print("RECEIVED")
var applicationDict = Dictionary<String, Array<AnyObject>>()
applicationDict = file.metadata as! Dictionary<String, Array<AnyObject>>
self.fileArray = applicationDict["fileArray"]!
self.fileList = self.fileArray
let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let tempDocsDir = dirPaths[0] as String
let docsDir = tempDocsDir.appending("/")
let filemgr = FileManager.default
do {
let fileName = self.fileArray[0].object(at: 1) as! String
try filemgr.moveItem(atPath: file.fileURL.path, toPath: docsDir + fileName)
} catch let error as NSError {
print("Error moving file: \(error.description)")
}
self.loadTableData()
})
}
完整的錯誤信息
錯誤移動文件:錯誤域= NSCocoaErrorDomain代碼= 4 「‘5d1392cd-ACAC-4b99-abf5-50062e12dc14_95de54df-69b1-43df-BB90-cfac6fed3677.mp3’無法移動到‘文檔’,因爲無論是前者沒有按」 t 存在,或者包含後者的文件夾不存在。「 UserInfo = {NSSourceFilePathErrorKey =/Users/pknapp/Library/Developer/CoreSimulator/Devices/950FC0DA-C245-4326-8777-80CE765AF655/data/Containers/Data/PluginKitPlugin/73C0D94F-483C-4426-B052-001E8837D83A/Documents/Inbox /com.apple.watchconnectivity/FCE7E6CB-2452-4E0A-9AFF-F5B3A51A0DE8/Files/0B96CCB0-A2E1-418B-9859-97C22238A5F5/5d1392cd-acac-4b99-abf5-50062e12dc14_95de54df-69b1-43df-bb90-cfac6fed3677.mp3,NSUserStringVariant =( 移動),NSFilePath = /用戶/ pknapp /庫/開發商/ CoreSimulator /設備/ 950FC0DA-C245-4326-8777-80CE765AF655 /數據/容器/數據/ PluginKitPlugin/73C0D94F-483C-4426-B052-001E8837D83A /文件/Inbox/com.apple.watchconnectivity/FCE7E6CB-2452-4E0A-9AFF-F5B3A51A0DE8/Files/0B96CCB0-A2E1-418B-9859-97C22238A5F5/5d1392cd-acac-4b99-abf5-50062e12dc14_95de54df-69b1-43df-bb90-cfac6fed3677.mp3 ,NSDestinationFilePath = /用戶/ pknapp /庫/開發商/ CoreSimulator /設備/ 950FC0DA-C245-4326-8777-80CE765AF655 /數據/ CONTA iners/Data/PluginKitPlugin/73C0D94F-483C-4426-B052-001E8837D83A/Documents/5d1392cd-acac-4b99-abf5-50062e12dc14_95de54df-69b1-43df-bb90-cfac6fed3677.mp3,NSUnderlyingError = 0x7b776110 {Error Domain = NSPOSIXErrorDomain Code = 2 「沒有這樣的文件或目錄」}}