Re: [問題] NSData writeToFile cocoa error 4

看板MacDev作者 (小朱)時間11年前 (2014/09/02 17:15), 10年前編輯推噓3(303)
留言6則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《issuemylove (skill)》之銘言: : 想請問各位大大 : 關於NSData的writeToFile正確用法。 : 我寫了如下程式碼來將我下載的圖片存入到ipad中: : 如圖 http://ppt.cc/UJAP : 但是一直發生 Cocoa error 4的錯誤,請問我是哪邊有弄錯嗎??? : log: http://ppt.cc/9Zsw : 謝謝大大們的幫助! 我用了點我的方法重新驗證原 PO 的問題,Code 如下: NSString *saveDirectory = [[DTFileController mainController] documentPathWithFileName:@"/my_images"]; [[DTFileController mainController] createDirectoryAtPath:saveDirectory]; NSString *savePath = [saveDirectory stringByAppendingPathComponent:@"image.jpg"]; NSData *imageData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"https://www.google.com.tw/images/srpr/logo11w.png"]]; NSError *error = nil; [imageData writeToFile:savePath options:NSDataWritingAtomic error:&error]; if (error != nil) { NSLog(@"%@", error); } 我是沒發生原 PO 的問題, 我的建立資料夾的參數 withIntermediateDirectories: 是 NO, 不過我用了 Yes 也沒問題, 所以還是不知道問題在哪裡, 不過原 PO 可以嘗試看看我寫的 DTFileController? https://github.com/Darktt/DTFileController --

為什麼手把是限制級!?

因為會震動啊~

3樓神回
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.117.153.197 ※ 文章網址: http://www.ptt.cc/bbs/MacDev/M.1409649303.A.28A.html

09/02 20:13, , 1F
我研究後再回覆QQ,不過目前感覺怪怪的就是了,若再奇怪會
09/02 20:13, 1F

09/02 20:13, , 2F
丟專案上來,謝謝大大們!
09/02 20:13, 2F

09/03 11:57, , 3F
我試了大大的library情況也是Cocoa Error 4
09/03 11:57, 3F

09/03 11:58, , 4F
我的專案檔案如:http://ppt.cc/6ki5
09/03 11:58, 4F
你的完整的 error 資料是: The operation couldn’t be completed. No such file or directory 我自己是不會只有 log error 的 localizedDescription 因為他的描述太片面了,log 完整的 error 的資料才能知道完整的原因。 ※ 編輯: darktt (122.117.153.197), 09/03/2014 13:11:16

09/03 14:25, , 5F
謝謝大大的幫助!上一篇已經找出我的問題了,我目錄
09/03 14:25, 5F

09/03 14:25, , 6F
沒有建立成功 (參數帶錯)orz 謝謝!
09/03 14:25, 6F
文章代碼(AID): #1K1OgNAA (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1K1OgNAA (MacDev)