带有UIDocumentPickerViewController的iOS自定义UTI / filetype

时间:2018-03-20 02:53:12

标签: ios uti uidocumentpickerviewcontroller

我有一个自定义文件类型,我试图允许我的应用程序从UIDocumentPickerViewController打开。然而,它并没有起作用。 (类似的情况和问题似乎在描述here,但没有可行的解决方案。)

在我的Info.plist中,我得到了:

library(dplyr)
df1 %>%
   group_by(grp =  cumsum(Anomaly != lag(Anomaly, default = Anomaly[1]))) %>% 
   filter(Anomaly == "Anomaly") %>% 
   summarise(Starttime = first(Starttime), Endtime = last(Endtime)) %>%
   rename(Anomaly = grp)
# A tibble: 2 x 3
#   Anomaly  Starttime           Endtime            
#   <int>    <dttm>              <dttm>             
#1     1 2018-01-31 08:10:31 2018-01-31 08:22:17
#2     3 2018-01-31 08:35:27 2018-01-31 08:49:08

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>myext</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>document.icns</string>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>My document</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.app.document</string>
        </array>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
</array>

我正在用以下内容实例化:

<key>UTImportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array/>
        <key>UTTypeDescription</key>
        <string>My document</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.app.document</string>
        <key>UTTypeSize320IconFile</key>
        <string>document</string>
        <key>UTTypeSize64IconFile</key>
        <string>document</string>
        <key>public.filename-extension</key>
        <array>
            <string>myext</string>
            <string>MYEXT</string>
        </array>
    </dict>
</array>

问题是,我的iCloud帐户中的“Test File I.myext”看起来像这样:

,即灰显的,不可选择的,无法识别的文件。

我希望我做的事情明显不对,但是我看不到它。

1 个答案:

答案 0 :(得分:0)

您必须输入以下内容:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeIconFiles</key>
                <array/>
                <key>CFBundleTypeName</key>
                <string>My Extension</string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>myext</string>
                </array>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>myext file</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.app.document.myext</string>
        </array>
    </dict>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>My Extension File</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.app.document.myext</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>myext</string>
            </array>
        </dict>
    </dict>
    <dict/>
</array>

还需要在控制器中输入以下内容:

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)

应该可以