Ios 在WKWebView目标c中打开PDF文件
我在使用WKWebView和objective c可视化pdf文件的内容时遇到问题。对不起,我不熟悉斯威夫特。下面是代码,但它显示一个空白页,并返回以下错误: 错误Domain=nscocaerorrordomain Code=261无法使用文本编码Unicode UTF-8打开文件“Sample1.pdf”Ios 在WKWebView目标c中打开PDF文件,ios,objective-c,pdf,wkwebview,wkwebviewconfiguration,Ios,Objective C,Pdf,Wkwebview,Wkwebviewconfiguration,我在使用WKWebView和objective c可视化pdf文件的内容时遇到问题。对不起,我不熟悉斯威夫特。下面是代码,但它显示一个空白页,并返回以下错误: 错误Domain=nscocaerorrordomain Code=261无法使用文本编码Unicode UTF-8打开文件“Sample1.pdf” 您不需要这样做: TextToBeDisplayed = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8String
您不需要这样做:
TextToBeDisplayed = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&err];
同样,在这种方法中,您将不会得到NSURLRequest,而是从PDF文件中尝试转换为NSURLRequest的某种文本
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:TextToBeDisplayed]];
您所需要的就是:
NSString *filePath;
filePath = [[NSBundle mainBundle] pathForResource:@"Sample1" ofType:@"pdf"];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];
[webView setBackgroundColor:[UIColor whiteColor]];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];
您不需要这样做:
TextToBeDisplayed = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&err];
同样,在这种方法中,您将不会得到NSURLRequest,而是从PDF文件中尝试转换为NSURLRequest的某种文本
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:TextToBeDisplayed]];
您所需要的就是:
NSString *filePath;
filePath = [[NSBundle mainBundle] pathForResource:@"Sample1" ofType:@"pdf"];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];
[webView setBackgroundColor:[UIColor whiteColor]];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];