diff options
Diffstat (limited to 'example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm')
-rwxr-xr-x | example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm | 13 |
1 files changed, 12 insertions, 1 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"]; |