ios - 关闭包含显示 PDF 的 WKWebView 的 ViewController 时触发 iOS 断言
问题描述
我在关闭UIViewController
. 有UIViewController
一个UIView
,我在其中添加了一个WKWebView
. WKWebView
我已经加载了一个 PDF 文件。PDF 显示和功能正常。当我关闭窗口时,Xcode 会报告一个断言:
-[PDFExtensionTopView _accessibilityUnregisterRemoteView]: unrecognized selector sent to instance
如果我有我的All Objective-C Exceptions
断点,执行就会停止。我可以继续,但这相当具有破坏性。用户从来没有看到任何问题,所以这纯粹是一个开发时的问题。我通过在使用此视图时禁用断点来解决此问题,但更愿意找到真正的修复程序。我在 Xcode 11.3.1 上,在这个类中使用 ObjC。
我创建了一个简化的虚拟项目。整个 UIViewController 的代码如下。它是从一个简单的 UIButton 呈现出来的,它不向这个 UIViewController 传递任何内容。
移动 displayPDF 方法调用在 中viewWillAppear
,但在 DidAppear、DidLoad 等中没有变化。它与特定的 PDF 无关(我尝试过来自多个来源的文件)。
如果我使用 displayHTML(将虚拟 HTML 放入 webView),我不会遇到问题。
我可能只是对 ObjC 生疏了,并且遗漏了一些明显的东西。有什么想法吗?
#import "MyPDFViewController.h"
#import <WebKit/WebKit.h>
@interface MyPDFViewController ()
@property (strong, nonatomic) IBOutlet UIView *pdfContainerView;
- (IBAction)closeButtonPressed:(id)sender;
@property (nonatomic, strong) WKWebView *webView;
@end
@implementation MyPDFViewController
-(void)viewWillAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self displayPDF];
}
-(void)displayPDF {
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyPDFFile" ofType:@"pdf"];
NSData *data = [NSData dataWithContentsOfFile:path];
self.webView = [[WKWebView alloc] initWithFrame:self.pdfContainerView.frame configuration:[[WKWebViewConfiguration alloc] init]];
[self.webView loadData:data MIMEType:@"application/pdf" characterEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@""]];
[self.pdfContainerView addSubview:self.webView];
}
-(void)displayHTML {
[self.webView loadHTMLString:@"<html><body>Hi.</body></html>" baseURL:nil];
}
- (IBAction)closeButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:^{
//
}];
}
@end
解决方案
推荐阅读
- java - 为什么一旦达到一定数量,进度就会减少?
- html - Bootstrap CSS - 媒体权限
- android - 关于如何执行延迟后台工作的即时应用程序建议
- javascript - Jquery - 对于每个等待显示模式
- apache-kafka - 如何从 yahoo kafka manager 连接到安全的 kafka 集群(SASL_SSL)?
- javascript - 想要解析主页上轮播的模态#
- java - 创建等效的动作
从 C# 在 Java 中 - batch-file - imagemagick 7.0.8-25 上的 .BAT 脚本创建转换文件的 LOG 和 TIMESTAMPS 的问题
- c# - 如何使用 linq 或 moreLinq 比较和合并列表
- json - 如何使用python Post请求将下拉列表参数添加到restapi url