简体   繁体   English

识别iOS文件包(在Simulator和Finder中)

[英]Recognizing iOS file packages (in Simulator and Finder)

I am trying to use file packages for an iOS app be defining an UTI type. 我正在尝试使用iOS应用程序的文件包来定义UTI类型。 After googling and looking at the entries in Xcode.plist, I tried a few things but kept running into problems. 在谷歌搜索并查看Xcode.plist中的条目后,我尝试了一些事情,但一直遇到问题。 My app creates a few test documents and then tries to read those files with my custom UTI. 我的应用程序创建了一些测试文档,然后尝试使用我的自定义UTI读取这些文件。

If I don't specify "LSItemContentTypes", then finder correctly sees them as packages. 如果我没有指定“LSItemContentTypes”,那么finder会正确地将它们视为包。 But then mdls returns "dyn.longstring" as kMDItemContentType. 但是mdls将“dyn.longstring”作为kMDItemContentType返回。

If I do specify "LSItemContentTypes", then the kMDItemContentType is correct. 如果我指定“LSItemContentTypes”,则kMDItemContentType是正确的。 But finder sees it as a folder. 但是finder将其视为文件夹。

In both cases the UTI I get via 在这两种情况下,我通过UTI

[url getResourceValue:&UTI
forKey:NSURLTypeIdentifierKey
error:nil];

is incorrect. 是不正确的。 It either returns "dyn.longstring" or "public.folder". 它要么返回“dyn.longstring”,要么返回“public.folder”。 My app doesn't load these files because of the incorrect UTI. 我的应用程序因为UTI不正确而未加载这些文件。 I could rewrite this but want to do it the right way with UTI's. 我可以改写这个但是想用UTI的正确方法做到这一点。

I defined an iOS file package as document type and exported UTI type as can be seen below. 我将iOS文件包定义为文档类型并导出UTI类型,如下所示。 What am I overlooking? 我在俯瞰什么?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>tdp</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MyFilePackage</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>reverse.dns.ios.package</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>Default</string>
        <key>LSIsAppleDefaultForType</key>
        <true/>
        <key>LSTypeIsPackage</key>
        <true/>
    </dict>
</array>
</plist>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename.extension</key>
            <array>
                <string>tdp</string>
            </array>
        </dict>
        <key>UTTypeIdentifier</key>
        <string>reverse.dns.ios.package</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>com.apple.package</string>
            <string>public.composite-content</string>
        </array>
    </dict>
</array>
</plist>

Was having a similar issue, including the UTI showing up as "dyn.longstring". 有一个类似的问题,包括UTI出现“dyn.longstring”。 Seems like the fix was to remove CFBundleTypeExtensions attribute (which is deprecated). 似乎修复是删除CFBundleTypeExtensions属性(不推荐使用)。 This combination in the info.plist worked for me: info.plist中的这个组合对我有用:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>My App Name</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>my.content.type</string>
        </array>
        <key>LSTypeIsPackage</key>
        <true/>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>com.apple.package</string>
            <string>public.composite-​content</string>
        </array>
        <key>UTTypeDescription</key>
        <string>My App Name</string>
        <key>UTTypeIdentifier</key>
        <string>my.content.type</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>myextension</string>
        </dict>
    </dict>
</array>

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

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