小编Ema*_*tti的帖子

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
查看次数

标签 统计

appdelegate ×1

file ×1

import ×1

ios ×1

swift ×1