【问题标题】:What is the proper way to handle imported files in iOS 9?在 iOS 9 中处理导入文件的正确方法是什么?
【发布时间】:2015-07-15 01:05:51
【问题描述】:
我的应用程序包含在其中打开 .plist 文件的功能。我的 info.plist 文件具有所有必要的权利,并且在我的应用程序中打开文档可以正常工作。问题是我不知道处理导入文件的正确方法,尤其是在 iOS 9 中不推荐使用 application:openURL:sourceApplication:annotation: 方法之后。此外,导入文件时,我的应用程序可能会打开到本地文件列表,所以我需要能够在收到文件时刷新该列表。
提前感谢您的帮助。
【问题讨论】:
标签:
ios
xcode
xcode7
ios9
【解决方案1】:
我想出了如何去做(虽然它可能不是正确的方法)。
- 在任何类声明之外使用
var fileURL: NSURL? 声明一个全局变量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)
}
}