aboutsummaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm13
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js7
2 files changed, 16 insertions, 4 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 5e89f33b..710c7c7a 100755
--- a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
@@ -146,7 +146,10 @@
NSString *filename = [NSString stringWithFormat:@"%lu", (unsigned long)urlString.hash];
NSURL *cacheURL = [self _cacheJPEGImageData:previewData withFilename:filename];
- NSString *replaceScript = [NSString stringWithFormat:@"replaceImageSrc(\"%@\", \"%@\")", urlString, cacheURL.absoluteString];
+ NSDictionary *args = @{ @"URLKey": urlString, @"LocalPathKey": cacheURL.absoluteString };
+ NSString *jsonString = [self _jsonEscapedStringFromDictionary:args];
+
+ NSString *replaceScript = [NSString stringWithFormat:@"replaceImageSrc(\"%@\")", jsonString];
[_webView stringByEvaluatingJavaScriptFromString:replaceScript];
};
@@ -160,6 +163,14 @@
}
}
+- (NSString *) _jsonEscapedStringFromDictionary:(NSDictionary *)dictionary {
+ NSData *json = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
+ NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
+ jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
+ jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
+ return jsonString;
+}
+
- (NSURL *) _cacheJPEGImageData:(NSData *)imageData withFilename:(NSString *)filename
{
NSString *path = [[NSTemporaryDirectory() stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"jpg"];
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js b/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js
index 67510c74..1078b04b 100644
--- a/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js
@@ -16,13 +16,14 @@ var findCIDImageURL = function() {
return JSON.stringify(imgLinks);
}
-var replaceImageSrc = function(original, local) {
+var replaceImageSrc = function(jsonString) {
+ var parsedJson = JSON.parse(jsonString);
var images = imageElements();
for (var i = 0; i < images.length; i++) {
var url = images[i].getAttribute('src');
- if (url.indexOf(original) == 0) {
- images[i].setAttribute('src', local);
+ if (url.indexOf(parsedJson.URLKey) == 0) {
+ images[i].setAttribute('src', parsedJson.LocalPathKey);
break;
}
}