What are UTImportedTypeDeclarations and UTExportedTypeDeclarations used for on iOS?

前端 未结 2 1875
北海茫月
北海茫月 2021-02-07 14:04

Am I facing a typo here or do really both variations exist on iOS:

  • UTImportedTypeDeclarations
  • UTExportedTypeDeclarations
2条回答
  •  名媛妹妹
    2021-02-07 14:23

    UTExportedTypeDeclarations

    You use UTExportedTypeDeclarations to define your own UTIs that your app wants to teach the system it is installed on. An UTI describes a piece of data (not necessarily data located inside a file!) and requires at least an identifier (com.example.MyCoolDataType). Additionally it may have a name (My Cool Data Type), one or more file name extensions (.myCoolDataType), one or more MIME types (x-application/my-cool-data-type), one or more pasteboard types (used when transferring data of that kind using copy&paste), and one or more legacy OS types (four character codes, not used by OS X any longer, that was the type system of MacOS 9 and earlier). Usually you also want UTIs to conform to existing UTIs, that way apps that don't know your UTI but that do know one of the UTIs it conforms to is still able to perform meaningful operations on it. E.g. when you say your UTI conforms to public.data, any process that can deal with generic data can also deal with your UTI as your UTI describes generic data.

    The system has a database of all known UTIs and when your application defines new UTIs, these are automatically added to the database and thus are known to the entire system. Please note that the fact, that your app defines these UTIs doesn't mean that it can also "handle" files containing data of that kind!

    Typical usage example:
    You define your own proprietary file data format and you want this data format to be also known to other apps, plugins, extensions, and so on.

    UTImportedTypeDeclarations

    You use UTImportedTypeDeclarations do teach the system about UTIs that you want to be known in the system but that are not your UTIs. The values are the same as for UTExportedTypeDeclarations and all the types are also added to the database and are thus visible throughout the entire system.

    The difference between UTExportedTypeDeclarations and UTImportedTypeDeclarations is only that you claim ownership of the UTIs in UTExportedTypeDeclarations, which means if the system already knows that UTI but the stored values are different than your values, your values update the stored values, as it is your UTI, so your description is always considered authoritative! In case of UTImportedTypeDeclarations, these are not even looked at for types already known to the system as what you say is not authoritative. These are only taken into account for types unknown so far and as soon any app lists the same UTIs under UTExportedTypeDeclarations, the values of that app override the values given by your app.

    Typical usage example:
    Your app is able to read the proprietary data format of another application, yet you don't know if that application is even installed on the system. To make that data format known, you declare it as import, since as soon as the user installs the app in question, you want that this app correctly defines the data format for you.

    CFBundleDocumentTypes

    You use CFBundleDocumentTypes to tell the system which Document types your app is able to open. Unless you also list your UTIs here, these UTIs are not associated with your app in Finder and your app won't appear in the Open With > menu. If you defined all your file types as UTIs, then all you need to provide for every document type is the UTI and the role. Things like the name, the icon, the file extensions, or the MIME types will all be taken from the UTI if not overridden by a document type. Note however, that you can define document types without defining an UTI, in that case you must set all these values directly on the document type. The only thing you always must set for a document type is the role. The role can be "Viewer" (you can display that file type but you cannot edit it), "Editor" (you can display and edit that file type), "None" (it's not specified what you can do with that file).

    Typical usage example:
    You want your app do be associated with certain file types, identified either by extension, by MIME type, or by UTI identifier. If you want your app to be associated with an UTI type, the app should either import or export the type, as otherwise the type may not be known to the system and registering to unknown UTI type has simply no effect at all.

提交回复
热议问题