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:
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:
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:
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.