I have this code to take a URL and get me a thumbnail of the page, but none of the delegate methods for UIWebView are being called:
It is printing out the log message above. It never prints out a log for either of these:
Thoughts? I want to get a thumbnail of a page and save it to my database and then show the thumbnail instead of the page itself.
Code:
CGFloat width = [[UIScreen mainScreen] applicationFrame].size.width;
CGFloat height = [[UIScreen mainScreen] applicationFrame].size.height;
CGFloat max = width > height?width:height;
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, max, max)];
webView.delegate = self;
NSLog(@"Load request: %@", @"https://www.macrumors.com");
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.macrumors.com"]]];
It is printing out the log message above. It never prints out a log for either of these:
Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"Load request finished");
UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *webViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(webViewImage);
Page *newPage = [NSEntityDescription insertNewObjectForEntityForName:@"Page" inManagedObjectContext:self.context];
newPage.thumbnail = imageData;
[self.collectionView reloadData];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"Load request failed: %@", error);
}
Thoughts? I want to get a thumbnail of a page and save it to my database and then show the thumbnail instead of the page itself.