Unable to select pre-registered files types using UIDocumentPickerViewController with with pre-iOS 14 target - swift

I'm using a document picker to import data into an app. One of the files to import is a .GPX (it's actually an XML file of GPS data, but that's not relevant). I define a custom file type (as it's not covered by the standard file types covered within UniformTypeIdentifiers)
let documentsPicker = UIDocumentPickerViewController(documentTypes: ["com.sourceapp.gpx"], in: .open)
and register it in info.plist as a Document type, and include this in Exported type identifiers and, seeing as it is not a bespoke file type, in Imported type identifiers. These are all still required as the app target is pre-iOS 14 (for 14+ it's not necessary to add the items to info.plist).
This works fine in the simulator where it's a clean environment without any other apps installed. On a device however it doesn't work, and the file is greyed out and not selectable. I'm reasonably certain this is because a custom file type with the same extension is already registered by another app.
So how do I go about using a file type that has already been registered? There must be a "correct" way to go about this as it must be a common scenario.
My understanding was that this is what the Imported type identifiers was for, but I can't seem to get this to work. This may be because I'm not defining the imported type in exactly the same way as the first app to register it.
If so, how do I see what has already been registered, and reuse it? This would need to be a generic apprach as a scenario where a different app has already regsitered the file type but in a different way is highly likely for a common file type such as .gpx
As background, when using a pre-defined file type such as "public.comma-separated-values-text" for a CSV file all works fine.
UPDATE:
I've since seen as the bottom line of documentation that the exported type identifiers overrides imported type identifiers, so have tried deleting the exported one, butit makes no difference.

Related

Why Doesn't Swift Package Manager Ask For A Filename?

In a regular Xcode project app, when I create a new file, it will offer me a template (eg. SwiftUI/Swift/Storyboard) to choose from. I choose a template, click on next, and the prompt will allow me to input the filename. After that, Xcode automatically generates the file with the filename given, the header filename, and the struct name in case of SwiftUI file.
However, in Swift Package Manager projects, creating a new file doesn't give me the chance to input a filename and creates a default Swift or SwiftUI file with placeholder names like file.swift.
Is this a known issue or bug? Why this behavior? Is there anyway to change this?
Question credit

iTunesLibrary Swift 5.3 macOS

After reading the documentation and looking through the header files of the iTunesLibrary frameworks I am unable to determine how, or if it's even possible, to manually specify the iTunes/Music library file to read?
The documentation within the header files indicate the system dynamic library loads the 'Default' library. The only way I have found so far to load another library is to use the +click method to manually choose the library to be used, then quit the Music app and the last chosen library become the default.
Is there not a way to specify a file? The mediaFolderLocation and musicFolderLocation methods are defined as 'get only' methods.
After lots and lots of research I have determined there is not a way to specify the particular library you want to open. It automatically refers to the system 'default' library.

Is it possible to change scope for parts of playground (to play with access control)

I curious is it possible to split Swift playground so that different parts will be in different source files, different modules?
Inside playground package I found file with format "section-1.swift", I tried to add "section-2.swift"... nothing. Any clues?
Update: I asked same question on dev forum https://devforums.apple.com/thread/239671?tstart=50
The "section" files inside a playground are all stitched together into a single implicit Swift source file, and treated as a single module.
To play with access control, you'll need to build an app project (possibly with an embedded framework target).

Creating your own UTI for an iOS app

The app I'm developing has a custom file format for its files, and I'd like to be able to use the "Open In ..." feature of iOS which lets users e.g. email each other a file and then open it directly in the app.
I've gotten as far as adding the CFBundleDocumentType stuff in the Info.plist file, but the problem is the LSItemContentTypes. From what I've read, I need to provide the actual file
as a UTI, rather than just saying ".myfileextension", and I can't find a lot about how to create UTI's in a iOS app.
Anyone know?
You will want to read up on the following topics from Apple:
Adopting Uniform Type Identifiers
Introduction to Uniform Type Identifiers Overview
Declaring New Uniform Type Identifiers
From the documentation:
If your application uses proprietary data formats, you should declare them in the Info.plist file of your application bundle. Some guidelines:
Your UTI string must be unique. Following the reverse-DNS format beginning with com.companyName is a simple way to ensure uniqueness. While the system can support different UTI strings with the same specification, the reverse is not true.
If your code relies on third-party UTI types that may not be present
on the system, you should declare
those UTIs as imported types in
your bundle.
Be sure to add conformance information if your proprietary type is a subtype of one or more existing types. In most cases you should not specify conformance to a nonpublic type, unless you are also declaring that type in your bundle. For a list of public and Apple-defined UTIs, see "System-Declared Uniform Type Identifiers"

Using info.plist for storing target-specific values for a multi-target app

I have a multi-target iPhone app which currently includes a header file with constant definitions that are conditionally included at build time depending on which target is being built.
However, I was wondering if it might be better to instead include this information in the info.plist for the build, as this generally holds target-specific meta, so logically seems more appropriate.
Therefore, my questions are:
Is it acceptable to include custom (non-Apple defined) keys in the info.plist file?
Is this a suitable place to include meta for the app which differ between targets?
It is acceptable and suitable.
The Info.plist file is preprocessed (must be enabled in project settings by setting Packaging / Preprocess Info.plist File to Yes) by the C pre-processor, so you can have variables (in the form of ${VARIABLE_NAME}). These variables can be defined in the User Defined section in Xcode's target info, making it very easy to switch their value from one target to another.