Posts

Post marked as solved
7 Replies
One possible workaround is to write the data into a file and then load the file URL but sometimes this is not a viable solution (e.g. client requirement that no data should be written unencrypted in the file system).Workaround without writing files on disk1. Use a custom scheme handlerWKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; id schemeHandler = ... [configuration setURLSchemeHandler:schemeHandler forURLScheme:@"someCustomScheme"]; WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];2. Load the data with that custom scheme:[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL urlWithString:@"someCustomScheme://name.rtf]]];3. In the scheme handler, provide the data in the protocol method:- (void)webView:(WKWebView *)webView startURLSchemeTask:(id)urlSchemeTask { NSData *data = ... NSURLResponse *workaroundResponse = [[NSURLResponse alloc] initWithURL:[NSURL urlWithString:@"someCustomScheme://name.rtf] MIMEType:@"application/rtf" expectedContentLength:data.length textEncodingName:@"utf-8"]; // These three methods must be called and exactly in this order, if not an exception will be thrown [urlSchemeTask didReceiveResponse:workaroundResponse]; [urlSchemeTask didReceiveData:data]; [urlSchemeTask didFinish]; }You can check a longer explanation and a working code sample here:https://github.com/elorz007/WKWebViewRTF