#pragma mark - ******************** 将发出通知时调用 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSString *url = request.URL.absoluteString; NSRange range = [url rangeOfString:@"sx:src="]; if (range.location != NSNotFound) { NSInteger begin = range.location + range.length; NSString *src = [url substringFromIndex:begin]; [self savePictureToAlbum:src]; return NO; } return YES; } #pragma mark - ******************** 保存到相册方法 - (void)savePictureToAlbum:(NSString *)src { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要保存到相册吗?" preferredStyle:UIAlertControllerStyleActionSheet]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSURLCache *cache =[NSURLCache sharedURLCache]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:src]]; NSData *imgData = [cache cachedResponseForRequest:request].data; UIImage *image = [UIImage imageWithData:imgData]; UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); }]]; [self presentViewController:alert animated:YES completion:nil]; }
浙公网安备 33010602011771号