Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSURLSessionDownloadTask *getImageTask = [session downloadTaskWithURL:[NSURL URLWithString:imageUrl]
- completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
- // Here you use the location variable provided in the completion handler to get a pointer to the image
- UIImage *downloadedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:location]];
- // Finally you could, for example, update UIImageView’s image to show the new file.
- dispatch_async(dispatch_get_main_queue(), ^{scheduleImage.image = downloadedImage;});
- // This is me trying to add stuff... downloading the image to a file
- NSString *imageName = [@"http://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" lastPathComponent];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- UIImage *imageToSave = [UIImage imageWithData:[NSData dataWithContentsOfURL:location]];
- NSData *binaryImageData = UIImagePNGRepresentation(imageToSave);
- [binaryImageData writeToFile:[basePath stringByAppendingPathComponent:imageName] atomically:YES];
- }];
- // You always have to start up the task!
- [getImageTask resume];
- }
Add Comment
Please, Sign In to add comment