使用 CFBundleDocumentTypes 过滤拖放 NSView

发布于 2024-12-18 06:32:28 字数 10165 浏览 6 评论 0 原文

我有一个拖放 NSView ,它应该接受与我在 plistCFBundleDocumentTypes 键下列出的相同的文件类型和扩展名。该应用程序接受 public.movi​​e 类型无法获取的任何类型的视频文件、文件夹和多个文件扩展名。

CFBundleDocumentTypes 的(相当长的)列表是:

    <key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Folder</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>fold</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Movies</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.movie</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>flv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Flash Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ram</string>
            <string>rm</string>
            <string>rmvb</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>RealPlayer Media Files</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>vob</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>VOB File (DVD Video)</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ogm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Ogg MPEG-4 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ogv</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/ogg</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Ogg Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>axv</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/annodex</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Annodex Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>avi</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>AVI container</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mov</string>
            <string>moov</string>
            <string>qt</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/quicktime</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Apple QuickTime container</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>divx</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>DivX file</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>dv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>DV file</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>wmv</string>
            <string>wm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Windows Media Video</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mpg</string>
            <string>mpeg</string>
            <string>mpeg1</string>
            <string>mpeg2</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>multiplexed MPEG-1/2</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>m1v</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-1 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ts</string>
            <string>m2ts</string>
            <string>mts</string>
            <string>mt2s</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/mp2t</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-2 Transport Stream</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>m2v</string>
            <string>mpv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-2 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mp4</string>
            <string>mpeg4</string>
            <string>m4v</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-4 File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>3gp</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>3GPP File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mkv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Matroska Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>webm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>WebM Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>nuv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>NuppleVideo File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
</array>

我已经能够在 NSView 的 draggingEntered 方法中验证放置接受情况,但我希望能够运行 CFBundleDocumentTypes 的 >Info.plist 条目,而不是复制此方法中的所有条目。如何执行此操作,以便我的视图接受与 CFBundleDocumentTypes 条目中列出的完全相同的文件?

I have a Drag/Drop NSView which should accept the same file types and extensions that I have listed in my plist under the key CFBundleDocumentTypes. The app accepts any type of video file, folders and several file extensions that aren't picked up by the public.movie type.

The (rather long) list of CFBundleDocumentTypes is:

    <key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Folder</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>fold</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Movies</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.movie</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>flv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Flash Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ram</string>
            <string>rm</string>
            <string>rmvb</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>RealPlayer Media Files</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>vob</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>VOB File (DVD Video)</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ogm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Ogg MPEG-4 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ogv</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/ogg</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Ogg Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>axv</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/annodex</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Annodex Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>avi</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>AVI container</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mov</string>
            <string>moov</string>
            <string>qt</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/quicktime</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Apple QuickTime container</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>divx</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>DivX file</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>dv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>DV file</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>wmv</string>
            <string>wm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Windows Media Video</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mpg</string>
            <string>mpeg</string>
            <string>mpeg1</string>
            <string>mpeg2</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>multiplexed MPEG-1/2</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>m1v</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-1 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ts</string>
            <string>m2ts</string>
            <string>mts</string>
            <string>mt2s</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>video/mp2t</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-2 Transport Stream</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>m2v</string>
            <string>mpv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-2 Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mp4</string>
            <string>mpeg4</string>
            <string>m4v</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-4 File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>3gp</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>3GPP File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mkv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Matroska Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>webm</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>WebM Video File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>nuv</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>NuppleVideo File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
</array>

I am already able to verify drop acceptance in my NSView's draggingEntered method, but I want to be able to run through the Info.plist entries for CFBundleDocumentTypes instead of duplicating all the entries in this method. How can I do this so that my view accepts the exact same files as listed in the CFBundleDocumentTypes entry?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2024-12-25 06:32:28

只需向您的包询问信息即可:

NSArray* documentTypes = [[[NSBundle mainBundle] infoDictionary]
                                    objectForKey:@"CFBundleDocumentTypes"];

这将返回一个字典数组,每个字典对应一种文件类型,您可以轻松地从中提取其他信息:

for(NSDictionary* docInfo in documentTypes)
{
    NSArray* fileExtensions = [docInfo objectForKey:@"CFBundleTypeExtensions"];
    //do something with this info
}

您可以将其与 -documentClassForType:NSDocumentController 的 code> 方法。这将 CFBundleTypeName Info.plist 键中的值作为类型。

Just ask your bundle for the information:

NSArray* documentTypes = [[[NSBundle mainBundle] infoDictionary]
                                    objectForKey:@"CFBundleDocumentTypes"];

This will return an array of dictionaries, one for each of the file types, from which you can easily extract the other information:

for(NSDictionary* docInfo in documentTypes)
{
    NSArray* fileExtensions = [docInfo objectForKey:@"CFBundleTypeExtensions"];
    //do something with this info
}

You could use this in conjunction with the -documentClassForType: method of NSDocumentController. This takes the value from the CFBundleTypeName Info.plist key as the type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文