显示内容

问题描述:

我有一个配置,以便在其他应用程序如邮件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 
} 

在AppDelegate中的didFinishLaunchingWithOptions,你可以处理设置你的用户界面来显示PDF。您可以使用UIWebView来呈现文档。

iPhone : can we open pdf file using UIWebView?

编辑:

This link解释,你可以聆听到AppDelegate中的启动选项。 didFinishLaunchingWithOptions。 UIApplicationLaunchOptionsURLKey将包含指向您的文件的URL。

+0

但实际上,我怎么当它在我的应用程序打开时访问PDF? –

+0

我发现此链接可能有所帮助: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/OpeningSupportedFileTypes.html#//apple_ref/doc/uid/TP40010412-SW1 – 72A12F4E

+0

因此,我在上面添加了一些我的AppDelegate.swift代码,我试图用PDF打开该应用程序,如果它的确如此,我假设用我编写的代码显示了一个alertview,我这样做是因为我意识到如果我关闭我的iPhone上的应用程序,然后连接与xcode上的控制台一起消失。无论哪种方式,我无法得到alertview显示哪个假设我在这里做错了什么。 –