我有一个可以打开 PDF 文件的应用程序。我已将此应用程序注册为外部 PDF 查看器。当我有一个 PDF 文件并单击共享按钮时,我会看到我的应用程序。如果我从外部源打开 PDF 文件,PDF 将被复制到内部应用程序存储“.../Documents/Inbox”。
如何检测我的应用程序是否以这种方式启动?我需要检测是否是,并使用新的 PDF 文件显示 PDFViewController。
我可以从“收件箱”读取数据,但无法检测到“应用程序启动类型”。以及如何检测新的 pdf 文件?按创建日期排序并获得第一?
应用委托:
func applicationWillEnterForeground(_ application: UIApplication) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "openPdfFromExternalSource"), object: nil)
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
在 PDFViewController 我有:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.ShowPdfFile), name: NSNotification.Name(rawValue: "openPdfFromExternalSource"), object: nil)
}