aboutsummaryrefslogtreecommitdiffhomepage
path: root/example/ios
diff options
context:
space:
mode:
authorGravatar Jonathan Willing <jwilling@me.com>2013-05-14 00:09:58 -0500
committerGravatar Jonathan Willing <jwilling@me.com>2013-05-14 00:09:58 -0500
commit027cbae7a9359b38661e6a576826f15909dc5286 (patch)
tree95c06efeb63d375efe3747ae9336e9657080578c /example/ios
parenta155ec4572cd1af580ea8da7a2c8748fa7002f6a (diff)
factor out code to handle case where we've already fetched the iamge
Diffstat (limited to 'example/ios')
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm21
1 files changed, 14 insertions, 7 deletions
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
index 97946a96..5e89f33b 100755
--- a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
@@ -139,16 +139,23 @@
NSString * partUniqueID = [part uniqueID];
NSData * data = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
+
+ void (^replaceImages)(NSError *error) = ^(NSError *error) {
+ NSData * downloadedData = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
+ NSData * previewData = [[self delegate] MCOMessageView:self previewForData:downloadedData isHTMLInlineImage:[self _isCID:url]];
+ NSString *filename = [NSString stringWithFormat:@"%lu", (unsigned long)urlString.hash];
+ NSURL *cacheURL = [self _cacheJPEGImageData:previewData withFilename:filename];
+
+ NSString *replaceScript = [NSString stringWithFormat:@"replaceImageSrc(\"%@\", \"%@\")", urlString, cacheURL.absoluteString];
+ [_webView stringByEvaluatingJavaScriptFromString:replaceScript];
+ };
+
if (data == NULL) {
[[self delegate] MCOMessageView:self fetchDataForPartWithUniqueID:partUniqueID downloadedFinished:^(NSError * error) {
- NSData * downloadedData = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
- NSData * previewData = [[self delegate] MCOMessageView:self previewForData:downloadedData isHTMLInlineImage:[self _isCID:url]];
- NSString *filename = [NSString stringWithFormat:@"%lu", (unsigned long)urlString.hash];
- NSURL *cacheURL = [self _cacheJPEGImageData:previewData withFilename:filename];
-
- NSString *replaceScript = [NSString stringWithFormat:@"replaceImageSrc(\"%@\", \"%@\")", urlString, cacheURL.absoluteString];
- [_webView stringByEvaluatingJavaScriptFromString:replaceScript];
+ replaceImages(error);
}];
+ } else {
+ replaceImages(nil);
}
}
}