2

我有一个 Drag/DropNSView它应该接受我plist在 key下列出的相同文件类型和扩展名CFBundleDocumentTypes。该应用程序接受任何类型的视频文件、文件夹和不被该public.movie类型选择的多个文件扩展名。

(相当长的)列表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方法中验证 drop 接受,但我希望能够运行Info.plist条目CFBundleDocumentTypes而不是复制此方法中的所有条目。CFBundleDocumentTypes我怎样才能做到这一点,以便我的视图接受与条目中列出的完全相同的文件?

4

1 回答 1

1

只需向您的捆绑包询问信息:

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.

于 2011-11-28T23:27:19.213 回答