相关疑难解决方法(0)

NSFileManager.defaultManager().fileExistsAtPath返回false而不是true

这怎么可能?

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)

你可以看到它应该在哪里:

在此输入图像描述

到底是怎么回事?

nsfilemanager ios swift

36
推荐指数
2
解决办法
6610
查看次数

AppDelegate 或 SceneDelegate 从文件接收 URL,但底层文件不存在

我正在开发一个基于 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 中,标志LSSupportsOpeningDocumentsInPlaceUIFileSharingEnabled均设置为YES。有一个UTImportedTypeDeclarations列出了 .gpx 扩展名,以便“文件”应用程序自动选择我的应用程序以打开它。 …

import file ios appdelegate swift

3
推荐指数
1
解决办法
1636
查看次数

标签 统计

ios ×2

swift ×2

appdelegate ×1

file ×1

import ×1

nsfilemanager ×1