【问题标题】:Display Contents of PDF opened in iOS App (Swift)显示在 iOS App (Swift) 中打开的 PDF 的内容
【发布时间】:2015-07-21 19:24:38
【问题描述】:

我有一个应用程序被配置为在其他应用程序(如邮件)中使用 PDF,我可以按住 PDF,它可以打开以“在”我的应用程序中“打开”;我有这个工作并且我的应用程序打开了,但现在我想在我的应用程序中显示该文档,我该怎么做?我很确定我必须使用 AppDelegate,但我刚开始使用 Swift,完全迷失了方向,找不到可以帮助完成此任务的教程,因此我们将不胜感激。

AppDelegate.swift

类 AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let UIApplicationLaunchOptionsURLKey: String = ""

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if UIApplicationLaunchOptionsURLKey.isEmpty {
        print("String is empty.")
    }
    else{

    let alertView:UIAlertView = UIAlertView()
    alertView.title = "PDF UPLOAD"
    alertView.message = "??"
    alertView.delegate = self
    alertView.addButtonWithTitle("OK")
    alertView.show()
    }
    return true
}

【问题讨论】:

    标签: ios swift pdf


    【解决方案1】:

    在 AppDelegate 的 didFinishLaunchingWithOptions 中,您可以设置 UI 以显示 PDF。您可以使用 UIWebView 来呈现文档。

    iPhone : can we open pdf file using UIWebView?

    编辑:

    This link 解释了您可以在 AppDelegate 中监听的启动选项。 didFinishLaunchingWithOptions。 UIApplicationLaunchOptionsURLKey 将包含指向您的文件的 URL。

    【讨论】:

    • 但是当它在我的应用程序中打开时,我如何实际访问该 PDF?
    • 我发现这个链接可能会有所帮助:developer.apple.com/library/ios/documentation/FileManagement/…
    • 所以我在上面添加了一些 AppDelegate.swift 代码,我试图用 PDF 打开应用程序,如果是这样,我假设我编写的代码会显示一个警报视图,我做到了这是因为我意识到如果我关闭 iPhone 上的应用程序,那么与 xcode 上的控制台的连接就会消失。无论哪种方式,我都无法显示警报视图,它假设我在这里做错了。
    • 如果您需要在此处显示警报,请尝试this。我建议您实例化一个可以为您处理此交互的视图控制器。
    • 我不需要警报,我只是用它来测试我的方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2016-03-24
    • 2012-11-23
    • 1970-01-01
    相关资源
    最近更新 更多