Re: [問題] NSData writeToFile cocoa error 4

作者: darktt (小朱)   2014-09-02 17:14:56
※ 引述《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
作者: redok (火焰)   2014-09-02 20:13:00
我研究後再回覆QQ,不過目前感覺怪怪的就是了,若再奇怪會丟專案上來,謝謝大大們!
作者: issuemylove (NotLove)   2014-09-03 11:57:00
我試了大大的library情況也是Cocoa Error 4我的專案檔案如:http://ppt.cc/6ki5謝謝大大的幫助!上一篇已經找出我的問題了,我目錄沒有建立成功 (參數帶錯)orz 謝謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com