[英]Download an image from URL and store in device (can be Photos folder in iPod), NOT IN APPLICATION
我有一個關於從URL下載圖像的問題。 檢查后,我意識到可以下載圖像並將其存儲到應用程序中(將iPod連接到MAC並打開該應用程序,我可以找到剛剛從服務器下載的圖像),但是該圖像未出現在設備的Photos文件夾中(我的iPod)。 以下是我的代碼:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
[NSURLConnection connectionWithRequest:request delegate:self];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"pkm.jpg"];
NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
[thedata writeToFile:localFilePath atomically:YES];
我的應用程序的主要任務是從服務器(通過URL)下載圖像並將圖像存儲到Photo文件夾(或我可以創建的其他文件夾)中,然后使用該圖像設置iPod的背景。
有人見過這種情況嗎? 請給我任何解決此問題的想法。
不管怎么說,還是要謝謝你,
瑞安
您將需要將圖像保存到相冊,您可以為此使用ALAssetsLibrary類。 他們可能學起來有些陡峭,但功能非常強大。
或使用非常簡單的方法: UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
方法。 這只會將圖像保存到照片庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.