[英]What is the proper way to handle imported files in iOS 9?
我的應用程序可以在其中打開.plist文件。 我的info.plist文件具有所有必要的權利,並且在我的應用程序中打開文檔工作正常。 問題是我不知道處理導入文件的正確方法,尤其是在iOS 9中不推薦使用application:openURL:sourceApplication:annotation:
方法之后。另外,我的應用程序可能會打開本地文件列表當導入文件時,因此我需要能夠在收到文件時刷新該列表。
在此先感謝您的幫助。
我想出了辦法(盡管可能不是正確的方法)。
NSURL?
的全局變量fileURL
NSURL?
使用var fileURL: NSURL?
在任何類聲明之外。 在AppDelegate.swift中實現以下方法:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool fileURL = url // The next two lines make sure the app open up to the first screen (the one marked as "Is Initial View Controller" in the Main.storyboard file. // If you would like to handle the file in a different ViewController then you will need to modify the code below. let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() self.window?.rootViewController = rootViewController return true }
在UIViewController的類聲明(或子類,如UITableViewController )中,實現以下方法:
override func viewDidAppear(animated: Bool) { if fileURL != nil { // handle file actions here (don't forget to use fileURL! not fileURL) } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.