简体   繁体   English

在“Files”应用程序中点击文件时iOS打开应用程序

[英]iOS open app when file is tapped in `Files` app

Some iOS apps with custom file types get launched automatically when a file of that type is tapped (for example, Pages gets launched if a pages file is tapped in the Files app). 当点击该类型的文件时,某些具有自定义文件类型的iOS应用程序会自动启动(例如,如果在“文件”应用程序中点击了页面文件,则会启动“页面”)。 How can an iOS app which is the owner of a UTI get the same behavior? 作为UTI所有者的iOS应用程序如何获得相同的行为? (The UTI in particular conforms to com.apple.package ) (特别是UTI符合com.apple.package

I'm using the sample BeerTracking app from https://www.raywenderlich.com/133825/uiactivityviewcontroller-tutorial . 我正在使用https://www.raywenderlich.com/133825/uiactivityviewcontroller-tutorial中的 BeerTracking示例应用程序。 When a file exported from the app is tapped in the Files app / Mail / Notes, an empty quicklook preview UI appears and only then is the user able to open the file in app by tapping share. 当在应用程序/邮件/便笺中点击从应用程序导出的文件时,会出现一个空的quicklook预览UI,然后用户才能通过点击共享在应用程序中打开该文件。

In the info.plist add the key "Supports opening documents in place" of type BOOLEAN and set it to TRUE. 在info.plist中添加BOOLEAN类型的键“支持打开文档”并将其设置为TRUE。

You can than check with 你可以检查

BOOL openInPlace = [options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue];

in

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options

if the provided url is a file that should be opened in place (most likely from the files app). 如果提供的URL是应该在适当位置打开的文件(很可能来自文件应用程序)。

At first you need to enable File Sharing . 首先,您需要启用文件共享 By add this 2 keys value YES in your Info.plist file 通过在Info.plist文件中添加此2键值YES

    1. UIFileSharingEnabled UIFileSharingEnabled
    2. LSSupportsOpeningDocumentsInPlace LSSupportsOpeningDocumentsInPlace

** You can do more stuff by using UIDocumentInteractionController link - https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller **您可以使用UIDocumentInteractionController链接执行更多操作 - https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller

  • To open a file type from iOS files app to your app, you need to have the cloud share functionality in your app so your app can share files into iCloud in a folder named by you app. 要从iOS文件应用程序打开文件类型到您的应用程序,您需要在您的应用程序中拥有云共享功能,以便您的应用程序可以在您的应用程序命名的文件夹中将文件共享到iCloud。

  • Then you can share any files to iCloud drive and they will show up in the iOS default files app. 然后,您可以将任何文件共享到iCloud驱动器,它们将显示在iOS默认文件应用程序中。

  • When you tap any files from there (example - image, pdf, video) they will open in your app. 当您点击那里的任何文件(例如 - 图像,PDF,视频)时,它们将在您的应用中打开。

    UIFileSharingEnabled will do the work from you. UIFileSharingEnabled将完成你的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM