Permalink
Browse files

[ios] Fix opening filenames, getting contact suggestions, #594

  • Loading branch information...
charlag committed Sep 11, 2018
1 parent 9e9c238 commit 88053e716c3445fef07e14fddf7a0ade4c1a80ea
Showing with 6 additions and 22 deletions.
  1. +2 −3 app-ios/tutanota/Sources/TUTViewController.m
  2. +4 −19 src/native/NativeWrapper.js
@@ -248,10 +248,9 @@ - (void) sendResponseWithId:(NSString *)responseId type:(NSString *)type value:(

- (void) postMessage:(NSDictionary *)message {
let jsonData = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
let jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
let escapted = [jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
let js = [NSString stringWithFormat:@"tutao.nativeApp.handleMessageFromNative('%@')", escapted];
let base64 = [jsonData base64EncodedStringWithOptions:0];
let js = [NSString stringWithFormat:@"tutao.nativeApp.handleMessageFromNative('%@')", base64];
[self->_webView evaluateJavaScript:js completionHandler:nil];
});
}
@@ -4,6 +4,7 @@ import {ConnectionError} from "../api/common/error/RestError"
import {asyncImport, defer, neverNull} from "../api/common/utils/Utils"
import {isMainOrNode, Mode} from "../api/Env"
import {getMimeType, getName, getSize} from "./FileApp"
import {base64ToUint8Array, utf8Uint8ArrayToString} from "../api/common/utils/Encoding"

/**
* Invokes native functions of an app. In case this is executed from a worker scope, the invocations are passed to the
@@ -112,25 +113,9 @@ class NativeWrapper {
}
}

handleMessageFromNative(msg: string) {
// replace illegal chars in json strings (some special strings like \t are replaced during a native invocation with their corresponding unicode chars)
let fixedMsg = msg.replace(/([\b\f\n\r\t])/g, (match) => {
switch (match) {
case "\b":
return "\\b"
case "\f":
return "\\f"
case "\n":
return "\\n"
case "\r":
return "\\r"
case "\t":
return "\\t"
default:
throw new Error("illegal match " + match + " of " + msg)
}
})
neverNull(this._nativeQueue)._handleMessage(JSON.parse(fixedMsg))
handleMessageFromNative(msg64: string) {
const msg = utf8Uint8ArrayToString(base64ToUint8Array(msg64))
neverNull(this._nativeQueue)._handleMessage(JSON.parse(msg))
}

_replacement(char: string) {

0 comments on commit 88053e7

Please sign in to comment.