2015-07-21 165 views
0

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

回答

0

在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顯示哪個假設我在這裏做錯了什麼。 –