这怎么可能?
let exists = NSFileManager.defaultManager().fileExistsAtPath(path.absoluteString)
print("exists: \(exists)") //false
Run Code Online (Sandbox Code Playgroud)
这是 path.absoluteString
//file:///Users/kuna/Library/Developer/CoreSimulator/Devices/92BD140D-5C14-43C4-80D6-904BB9594ED6/data/Containers/Data/Application/5B818832-BB19-4047-A7F8-1487F36868D6/Documents/wishlists/68/147/128/IMG_0006.PNG
Run Code Online (Sandbox Code Playgroud)
你可以看到它应该在哪里:
到底是怎么回事?
我正在开发一个基于 MapKit 的 iOS 路由应用程序,其中我实现了对以 GPX 开放标准(本质上是 XML)编写的文件的支持,以编码有关路由的所有用户信息,这些信息可以导出或导入以用于备份目的。
当用户在应用程序中导回 GPX 文件时,我可以通过将文件共享到应用程序来通过“文件”应用程序来完成此操作。执行此操作时,AppDelegate 或 SceneDelegate 会根据当前 iOS 版本拦截文件 URL:
在 AppDelegate 中(<= 12.4):
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Handle the URL in the url variable
}
Run Code Online (Sandbox Code Playgroud)
在 SceneDelegate (>= 13) 中:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
// Handle the URL in the URLContexts.first?.url
}
Run Code Online (Sandbox Code Playgroud)
在我的 Info.plist 中,标志LSSupportsOpeningDocumentsInPlace和UIFileSharingEnabled均设置为YES。有一个UTImportedTypeDeclarations列出了 .gpx 扩展名,以便“文件”应用程序自动选择我的应用程序以打开它。 …