-1

I have followed this tutorial and several others to try and create my CSS file type.

I also saw this tutorial even though I am using Visual Studio for Mac.

So I manually edited the Info.plist and added the following entries:

It has the following:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Cascade Style Sheet</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>co.uk.trucklesoft.ElderlyRota.css</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Cascade Style Sheet</string>
        <key>UTTypeIdentifier</key>
        <string>co.uk.trucklesoft.ElderlyRota.css</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>css</string>
        </dict>
    </dict>
</array>

In my app I am using the Xamarin.CommunityToolkit.FilePicker and it is set like this:

async private void InstallStyleButton_Clicked(object sender, EventArgs e)
{
    var customFileType =
        new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
        {
            {DevicePlatform.iOS, new[] { "co.uk.trucklesoft.ElderlyRota.css" } },
            {DevicePlatform.macOS, new[] {"css"} }
        });

    var pickResult = await FilePicker.PickAsync(new PickOptions
    {
        FileTypes = customFileType,
        PickerTitle = "Select stylesheet to install"

    });

    if(pickResult != null)
    {
        // Build target path (don't use hardcoded path)
        string targetFile = Path.Combine(_pageModel.StylesPath, pickResult.FileName);

        // OK to install?
        if(!File.Exists(targetFile)) 
        {
            // Install
            File.Copy(pickResult.FullPath, targetFile);

            // Add it
            StylesPicker.ItemsSource.Add(pickResult.FileName);

            // Select it
            StylesPicker.SelectedItem = pickResult.FileName;
        }
        
    }
}

When I start the Debugger in Visual Studio and try to click my Install button and navigate to a folder on the iCloud where I have CSS files:

enter image description here

I have highlighted the 3 files that are css files. I can't select them. If I remove the iOS entry from my FileTypePicker object then I can pick them because nothing is being filtered out. And the macOS filter works anyway.

What am I doing wrong?


Update

Visual Studio for Mac does not expose all of the properties in the Advanced tab:

enter image description here

So the others that were indicated I manually added.

Grateful for assistance.


Update 2

I followed another tutorial so now I have:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Cascade Style Sheet</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>co.uk.trucklesoft.ElderlyRota.CascadeStyleSheet</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Cascade Style Sheet</string>
        <key>UTTypeIdentifier</key>
        <string>co.uk.trucklesoft.ElderlyInfirm.CascadeStyleSheet</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeTagSpecification</key>
        <dict/>
        <key>public.filename-extension</key>
        <array/>
        <key>Item 0</key>
        <string>css</string>
        <key>Item 1</key>
        <string>CSS</string>
    </dict>
</array>

But still nothing. Two days of searching now. I keep going.


Update 3

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Cascade Style Sheet</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>co.uk.trucklesoft.ElderlyRota.css</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Cascade Style Sheet</string>
        <key>UTTypeIdentifier</key>
        <string>co.uk.trucklesoft.ElderlyInfirm.css</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
            <string>public.plain-text</string>
        </array>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>css</string>
                <string>CSS</string>
            </array>
        </dict>
    </dict>
</array>

I fixed some issues with the code. Now my picker is calling co.uk.trucklesoft.ElderlyRota.css as the file type. But still doesn't work in the simulator.


I noticed in Visual Studio for Mac

Every time I reopen my iOS project the info list reverts to:

enter image description here

See? It keeps resetting two of those elements. I expect this is part of the problem. Bug?

It is not a bug. VS for Mac just shows those labels but internally has the correct terms.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

2 Answers2

0

Does this help? It is further explanation of one of SO answers you posted as your starting point.

https://stackoverflow.com/a/2781290/7778287

user7778287
  • 367
  • 1
  • 11
0

After two days of searching I came across a valuable article:

Cascading Style Sheet (CSS) File Format

In that article is had details about the UTType:

enter image description here

The key information being:

  • public.css
  • text/css

Here it states:

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.

All I was doing was exporting. This is my final Info.plist content:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Cascade Style Sheet</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>co.uk.trucklesoft.ElderlyRota.css</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Cascade Style Sheet</string>
        <key>UTTypeIdentifier</key>
        <string>co.uk.trucklesoft.ElderlyInfirm.css</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.css</string>
        </array>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>css</string>
            <key>public.mime-type</key>
            <string>text/css</string>
        </dict>
    </dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Cascade Style Sheet</string>
        <key>UTTypeIdentifier</key>
        <string>public.css</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>text/css</string>
        </array>
    </dict>
</array>

In Visual Studio for Mac it looks like this in the Advanced tab:

enter image description here

I am not 100% sure if I still need to export the file type any more but I kept it in just incase. I know that imported file types will take precedence.

When I run my app now:

enter image description here

All the CSS files are available.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164