Note that there are some explanatory texts on larger screens.

plurals
  1. POImage doesn't save from URL when using UIImage
    primarykey
    data
    text
    <p>"img" is actually a string with an URL in it, but I actually use it also as the name of the file</p> <pre><code>NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:img]; NSURL *url = [NSURL URLWithString:img]; NSData *imageData = [NSData dataWithContentsOfURL:url]; [imageData writeToFile:storePath atomically:TRUE]; </code></pre> <p>In my view controller I got this:</p> <pre><code>UIImage *img = [[UIImage alloc] initWithContentsOfFile:self.initialImg]; if(img == nil) NSLog(@"image is nil"); [self.image setImage:img]; </code></pre> <p>"initialImg" is an NSString with the same url as in "img". I also changed "img" and "initialImg" with another string like test.png, but this doesn't work either.</p> <p>It prints out "image is nil" and not sure why it is nil...</p> <p><strong>EDIT:</strong></p> <p>Now I got:</p> <pre><code> NSURL *url = [NSURL URLWithString:img]; NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *uiImage=[UIImage imageWithData:imageData]; NSData *pngData = UIImagePNGRepresentation(uiImage); NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; [pngData writeToFile:filePath atomically:YES]; </code></pre> <p>And in another view controller in the viewDidLoad function:</p> <pre><code> UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"image.png"]; if(img == nil) NSLog(@"image is nil"); [self.image setImage:img]; </code></pre> <p>It still shows me "image is nil" and I changed the urls but they are correct</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload