在我的Swift应用程序中,用户可以将PDF文档目录中的PDF导入到tableview中。
我希望如果用户使用iOS 11的功能更新PDF,允许在文档上绘图,PDF将在应用程序中更新。但是这些更新不会出现在应用程序中,即使用户删除了原始条目并重新导入它。
更新文件的网址是否已经以某种方式发生了变化?如何让我的应用程序识别该文件已被用户更改?
谢谢,
利
我的didSelectRowAt:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let navController = splitViewController?.viewControllers[1] as? UINavigationController else { return }
guard let viewController = navController.viewControllers[0] as? ViewController else { return }
let cell = tableView.cellForRow(at: indexPath) as! UITableViewCell
let labelContent = cell.textLabel?.text
print (labelContent as Any)
//User tapped a built-in page
if labelContent?.range(of:"✡️") != nil {
fileIsFromService = false
print ("It's a built-in page")
var newURL = Bundle.main.url(forResource: items[indexPath.section][indexPath.row], withExtension: "pdf")
path = newURL
newBook = path.lastPathComponent
print ("The url to be passed is \(path)")
indexPoint = indexPath.row
print ("indexPoint is now \(indexPoint)")
viewController.load(items[indexPath.section][indexPath.row])
}
else {
//User selected a document from the device's directory
fileIsFromService = true
indexPoint = indexPath.row
let fileExists = FileManager().fileExists(atPath: (String(describing:(newDoc))))
if !fileExists {
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
finalDocURL = documentDirectory.appendingPathComponent(items[indexPath.section][indexPath.row])
path = finalDocURL
newDoc = path.lastPathComponent
indexPoint = indexPath.row
viewController.load(items[indexPath.section][indexPath.row])
}
}
}
我的didPickDocumentAt:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
do {
try FileManager.default.moveItem(at: url.standardizedFileURL, to: documentDirectory.appendingPathComponent(url.lastPathComponent))
} catch {
print(error)
}
finalDocURL = documentDirectory.appendingPathComponent(url.lastPathComponent)
newDoc = finalDocURL.lastPathComponent
if !items.joined().contains(newDoc) {
userDocs.append(newDoc)
defaults.set(userDocs,forKey:"UserDocs")
items[4].append(userDocs.last!)
defaults.set(items,forKey:"Items")
tableView.reloadData()
print ("Success")
alertSuccess()
}
else {
print ("I already have this document")
}
print ("I'm reloading...")
tableView.reloadData()
}