diff --git a/Common/Common.csproj b/Common/Common.csproj index 3c3f7fe..d38d9c3 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -15,7 +15,7 @@ - - + + \ No newline at end of file diff --git a/Windows/Common/Core/Common.Windows.Core.csproj b/Windows/Common/Core/Common.Windows.Core.csproj index a7adf16..edb836e 100644 --- a/Windows/Common/Core/Common.Windows.Core.csproj +++ b/Windows/Common/Core/Common.Windows.Core.csproj @@ -1,6 +1,6 @@ - net9.0-windows10.0.19041.0;net48 + net10.0-windows10.0.19041.0;net48 True Contains functionality common for all Windows Virtual Drive samples. IT Hit LTD. @@ -16,15 +16,15 @@ - - + + - + - - + + \ No newline at end of file diff --git a/Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj b/Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj index 99c3e53..02e1dac 100644 --- a/Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj +++ b/Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj @@ -1,6 +1,6 @@ - net9.0-windows10.0.19041.0 + net10.0-windows10.0.19041.0 Contains functionality common for all Windows Virtual Drive samples. IT Hit LTD. IT Hit User File System @@ -13,8 +13,8 @@ - - + + diff --git a/Windows/VirtualDrive/VirtualDrive.csproj b/Windows/VirtualDrive/VirtualDrive.csproj index 4848305..fe7ef56 100644 --- a/Windows/VirtualDrive/VirtualDrive.csproj +++ b/Windows/VirtualDrive/VirtualDrive.csproj @@ -1,7 +1,7 @@ WinExe - net9.0-windows10.0.19041.0 + net10.0-windows10.0.19041.0 10.0.19041.0 VirtualDrive Images\AppIcon.ico @@ -222,18 +222,18 @@ - - - - - - - + + + + + + + - - - + + + diff --git a/Windows/VirtualFileSystem/VirtualFileSystem.csproj b/Windows/VirtualFileSystem/VirtualFileSystem.csproj index d39b14d..1376f67 100644 --- a/Windows/VirtualFileSystem/VirtualFileSystem.csproj +++ b/Windows/VirtualFileSystem/VirtualFileSystem.csproj @@ -1,7 +1,7 @@ Exe - net9.0-windows10.0.19041.0 + net10.0-windows10.0.19041.0 IT Hit LTD. IT Hit LTD. Virtual File System @@ -32,10 +32,10 @@ This project does not support ETags, locking, Microsoft Office documents editing - + - + diff --git a/Windows/WebDAVDrive/WebDAVDrive.csproj b/Windows/WebDAVDrive/WebDAVDrive.csproj index c94b725..b8bd530 100644 --- a/Windows/WebDAVDrive/WebDAVDrive.csproj +++ b/Windows/WebDAVDrive/WebDAVDrive.csproj @@ -1,7 +1,7 @@ WinExe - net9.0-windows10.0.19041.0 + net10.0-windows10.0.19041.0 10.0.17763.0 WebDAV Drive Sample WebDAVDrive @@ -287,23 +287,23 @@ - + - - - - - - - - - - + + + + + + + + + + - - + + diff --git a/iOS/UserFileSystemSamplesiOS.sln b/iOS/UserFileSystemSamplesiOS.sln new file mode 100644 index 0000000..524da6f --- /dev/null +++ b/iOS/UserFileSystemSamplesiOS.sln @@ -0,0 +1,96 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebDAVDrive", "WebDAVDrive", "{DF07342E-8027-4D9E-E4F1-668290166881}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDAViOSApp", "WebDAVDrive\WebDAViOSApp\WebDAViOSApp.csproj", "{8DAF18DD-1317-414F-8F54-92651CCED21F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDAVFileProviderExtension", "WebDAVDrive\WebDAVFileProviderExtension\WebDAVFileProviderExtension.csproj", "{983895DD-CBD4-4EF8-8586-A505975FE56E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDAVCommon.iOS", "..\macOS\WebDAVDrive\WebDAVCommon\WebDAVCommon.iOS.csproj", "{A4B633BD-0405-4E35-9EB0-BDAFE3249923}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Core.iOS", "..\macOS\Common\Core\Common.Core.iOS.csproj", "{63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ITHit.FileSystem.Mac.iOS", "..\..\ITHit.FileSystem.Mac\ITHit.FileSystem.Mac.iOS.csproj", "{95C08764-E4DB-42B1-9B2C-A37661963527}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|x64.ActiveCfg = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|x64.Build.0 = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|x86.ActiveCfg = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Debug|x86.Build.0 = Debug|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|Any CPU.Build.0 = Release|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|x64.ActiveCfg = Release|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|x64.Build.0 = Release|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|x86.ActiveCfg = Release|Any CPU + {8DAF18DD-1317-414F-8F54-92651CCED21F}.Release|x86.Build.0 = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|x64.ActiveCfg = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|x64.Build.0 = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|x86.ActiveCfg = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Debug|x86.Build.0 = Debug|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|Any CPU.Build.0 = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|x64.ActiveCfg = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|x64.Build.0 = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|x86.ActiveCfg = Release|Any CPU + {983895DD-CBD4-4EF8-8586-A505975FE56E}.Release|x86.Build.0 = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|x64.ActiveCfg = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|x64.Build.0 = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|x86.ActiveCfg = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Debug|x86.Build.0 = Debug|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|Any CPU.Build.0 = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|x64.ActiveCfg = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|x64.Build.0 = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|x86.ActiveCfg = Release|Any CPU + {A4B633BD-0405-4E35-9EB0-BDAFE3249923}.Release|x86.Build.0 = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|x64.ActiveCfg = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|x64.Build.0 = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|x86.ActiveCfg = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Debug|x86.Build.0 = Debug|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|Any CPU.Build.0 = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|x64.ActiveCfg = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|x64.Build.0 = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|x86.ActiveCfg = Release|Any CPU + {63FD25B4-29C0-4688-B31D-C2B3DD1F86E6}.Release|x86.Build.0 = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|x64.ActiveCfg = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|x64.Build.0 = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|x86.ActiveCfg = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Debug|x86.Build.0 = Debug|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|Any CPU.Build.0 = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|x64.ActiveCfg = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|x64.Build.0 = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|x86.ActiveCfg = Release|Any CPU + {95C08764-E4DB-42B1-9B2C-A37661963527}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {8DAF18DD-1317-414F-8F54-92651CCED21F} = {DF07342E-8027-4D9E-E4F1-668290166881} + {983895DD-CBD4-4EF8-8586-A505975FE56E} = {DF07342E-8027-4D9E-E4F1-668290166881} + EndGlobalSection +EndGlobal diff --git a/iOS/WebDAVDrive/README.html b/iOS/WebDAVDrive/README.html new file mode 100644 index 0000000..b1a53d0 --- /dev/null +++ b/iOS/WebDAVDrive/README.html @@ -0,0 +1,143 @@ +

WebDAV Drive Sample for iOS in .NET, C#

+

This sample implements a virtual file system for iOS that displays documents from a WebDAV server. +It uses the iOS File Provider API (NSFileProviderReplicatedExtension, iOS 16+) and exposes +the virtual drive inside the iOS Files app.

+ +

Requirements

+
    +
  • .NET 8 SDK with the ios workload (sudo dotnet workload install ios)
  • +
  • Xcode 15+
  • +
  • iOS 16.0+ device or simulator
  • +
+ +

Solution Structure

+

The iOS sample mirrors the macOS sample: a container application registers the +File Provider domain and runs the WebSocket remote storage monitor, while the File Provider +extension (.appex) implements the virtual file system.

+

All virtual file system code (VirtualEngine, VirtualFolder, +VirtualFile, VirtualFileSystemItem, Mapping) and the +remote storage monitor (RemoteStorageMonitorBase, RemoteStorageMonitor, +ProtocolParameters) are shared with the macOS sample via linked files.

+

Shared libraries are built for iOS via companion projects that reference the same sources:

+
    +
  • Sources/ITHit.FileSystem.Mac/ITHit.FileSystem.Mac.iOS.csproj — engine, targets +net8.0-ios. FileProviderUI (FPUIActionExtensionViewController) is macOS-only +and excluded. NSDistributedNotificationCenter does not exist on iOS, so the engine +posts app↔extension notifications through files in the File Provider shared container +(NSFileProviderManager.DocumentStorageUrl) instead — see +InterprocessNotification.cs.
  • +
  • Samples/macOS/Common/Core/Common.Core.iOS.csproj
  • +
  • Samples/macOS/WebDAVDrive/WebDAVCommon/WebDAVCommon.iOS.csproj — excludes +AppKit/WebKit auth view controllers and security-scoped bookmark helpers.
  • +
+ +

Setting License

+

Set WebDAVClientLicense and UserFileSystemLicense in +Samples/macOS/WebDAVDrive/WebDAVMacApp/Resources/appsettings.json (the file is shared +with the macOS sample). The Engine can also run without an explicit license for a 5-day trial.

+ +

Setting WebDAV Server URL

+

Set WebDAVServerURLs and WebSocketServerUrl in +appsettings.json, or add a server URL in the app UI (+ button).

+ +

Running the Sample

+
    +
  1. Build: dotnet build ../UserFileSystemSamplesiOS.sln
  2. +
  3. For the iOS Simulator on Apple Silicon Macs use the x64 build (runs under Rosetta) — +dotnet build WebDAViOSApp/WebDAViOSApp.csproj -p:RuntimeIdentifier=iossimulator-x64.
    +Note: the arm64 simulator build currently fails to link native +System.Security.Cryptography symbols inside the File Provider extension; +this is a .NET iOS runtime-pack/app-extension interaction and does not affect device builds.
  4. +
  5. Deploy WebDAV Drive.app to a simulator (xcrun simctl install booted "WebDAV Drive.app") or a device.
  6. +
  7. In the app, tap a WebDAV server URL to mount it (registers the File Provider domain).
  8. +
  9. Open the Files app — the drive appears under Locations.
  10. +
+ +

Simulator troubleshooting

+
    +
  • Extension crashes on launch — the extension project uses the native static registrar +(<Registrar>static</Registrar>) and disables the managed debugger +(<MtouchDebug>false</MtouchDebug>) to avoid a Mono runtime assertion in the +system-launched extension process. It also includes the marshal-ilgen runtime component.
  • +
  • Files shows “content unavailable” after reinstalling — the simulator caches the extension +path from the previous install. Reboot the simulator to clear the cached service path: +xcrun simctl shutdown <uuid> then xcrun simctl boot <uuid> before installing again.
  • +
  • Mounting fails with a provisioning/app-group error — the unsigned simulator build does +not have a real app group entitlement. The UI and domain registration can still be tested, but +the full mount flow requires a signed build with a valid group.com.test.webdavdrive app group.
  • +
+

Testing on a physical iOS device

+

Testing the full File Provider mount flow on a real device requires an Apple Developer account, +signing, and an App Group. The simulator build can list the UI and register the domain, but the +shared container between the app and extension is not reliably available without real entitlements.

+ +

1. Apple Developer portal setup

+
    +
  1. Sign in to Apple Developer Center.
  2. +
  3. Go to Identifiers and create: +
      +
    • An App Group with identifier group.com.test.webdavdrive.
    • +
    • An App ID with Bundle ID com.test.webdavdrive.app. Enable the App Groups + capability and assign it to group.com.test.webdavdrive.
    • +
    • An App ID with Bundle ID com.test.webdavdrive.app.extension. Enable the App Groups + capability and assign it to group.com.test.webdavdrive.
    • +
    +
  4. +
  5. Register the iOS device(s) you will test on.
  6. +
  7. Go to Profiles and create an iOS App Development provisioning profile that includes + com.test.webdavdrive.app and com.test.webdavdrive.app.extension (multi-app profiles are allowed + for development) and your test device. Download and double-click to install it.
  8. +
  9. Make sure your Mac has a valid iPhone Developer certificate in Keychain Access.
  10. +
+ +

2. Project signing configuration

+

The Release configuration in both projects is already set up for device signing:

+
    +
  • WebDAViOSApp/WebDAViOSApp.csproj — CodesignKey=iPhone Developer, + CodesignEntitlements=Entitlements.plist, CodesignProvision=Automatic.
  • +
  • WebDAVFileProviderExtension/WebDAVFileProviderExtension.csproj — same settings.
  • +
+

You can override these from the command line if you have a specific certificate or provisioning +profile:

+
dotnet build WebDAViOSApp/WebDAViOSApp.csproj \
+  -c Release \
+  -p:RuntimeIdentifier=ios-arm64 \
+  -p:CodesignKey="Apple Development: Your Name (TEAMID)" \
+  -p:CodesignProvision="Your Dev Profile Name" \
+  -p:CodesignRequireProvisioningProfile=true
+
+ +

3. Deploy and run

+

Build an .app bundle for the device, then install and launch it. The simplest way is to let +dotnet deploy to the connected device:

+
dotnet build WebDAViOSApp/WebDAViOSApp.csproj \
+  -c Release \
+  -t:Run \
+  -p:RuntimeIdentifier=ios-arm64 \
+  -p:CodesignKey="Apple Development: Your Name (TEAMID)" \
+  -p:CodesignProvision="Your Dev Profile Name"
+
+

A convenience script is provided: build-device.sh. Set TEAM_ID and run it:

+
export TEAM_ID=ABCD123456
+./build-device.sh
+
+

Alternatively, build the .app and install it manually with xcrun devicectl or Xcode’s +Devices and Simulators window.

+ +

4. Test the provider

+
    +
  1. On the device, open Settings → General → VPN & Device Management and trust the developer.
  2. +
  3. Open the WebDAV Drive app and tap the WebDAV URL to mount it.
  4. +
  5. Open the Files app → Browse → WebDAV Drive.
  6. +
  7. Browse, open, edit, rename, and delete files against the WebDAV server.
  8. +
+ +

5. Common device errors

+
    +
  • “No valid provisioning profile” — the App Group is missing from one of the App IDs, or the + profile does not include the test device.
  • +
  • “The entitlements file requires the App Group ...” — the provisioning profile does not include + group.com.test.webdavdrive.
  • +
  • Files shows “content unavailable” — the extension process may have crashed. Check the device + console in Console.app for WebDAVFileProviderExtension crash logs.
  • +
diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png new file mode 100644 index 0000000..fbaa7c8 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png new file mode 100644 index 0000000..3f78ca1 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png new file mode 100644 index 0000000..2f698cb Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png new file mode 100644 index 0000000..903b830 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png new file mode 100644 index 0000000..08e6b29 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png new file mode 100644 index 0000000..27673a5 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png new file mode 100644 index 0000000..0afcd5d Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png new file mode 100644 index 0000000..9b72e39 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png new file mode 100644 index 0000000..7618174 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png new file mode 100644 index 0000000..903b830 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png new file mode 100644 index 0000000..2f6303b Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png new file mode 100644 index 0000000..08e6b29 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png new file mode 100644 index 0000000..07b6023 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png new file mode 100644 index 0000000..07b6023 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png new file mode 100644 index 0000000..fc448df Binary files /dev/null and b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..98cc5ef --- /dev/null +++ b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,116 @@ +{ + "images": [ + { + "filename": "AppIcon-iphone-20@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "20x20" + }, + { + "filename": "AppIcon-iphone-20@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "20x20" + }, + { + "filename": "AppIcon-iphone-29@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "29x29" + }, + { + "filename": "AppIcon-iphone-29@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "29x29" + }, + { + "filename": "AppIcon-iphone-40@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "40x40" + }, + { + "filename": "AppIcon-iphone-40@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "40x40" + }, + { + "filename": "AppIcon-iphone-60@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "60x60" + }, + { + "filename": "AppIcon-iphone-60@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "60x60" + }, + { + "filename": "AppIcon-ipad-20@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "20x20" + }, + { + "filename": "AppIcon-ipad-20@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "20x20" + }, + { + "filename": "AppIcon-ipad-29@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "29x29" + }, + { + "filename": "AppIcon-ipad-29@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "29x29" + }, + { + "filename": "AppIcon-ipad-40@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "40x40" + }, + { + "filename": "AppIcon-ipad-40@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "40x40" + }, + { + "filename": "AppIcon-ipad-76@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "76x76" + }, + { + "filename": "AppIcon-ipad-76@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "76x76" + }, + { + "filename": "AppIcon-ipad-83.5@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "83.5x83.5" + }, + { + "filename": "AppIcon-1024.png", + "idiom": "ios-marketing", + "scale": "1x", + "size": "1024x1024" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} \ No newline at end of file diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/Contents.json b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Entitlements.plist b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Entitlements.plist new file mode 100644 index 0000000..501890b --- /dev/null +++ b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Entitlements.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.com.test.webdavdrive + + + diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/Info.plist b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Info.plist new file mode 100644 index 0000000..362780f --- /dev/null +++ b/iOS/WebDAVDrive/WebDAVFileProviderExtension/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + WebDAVFileProviderExtension + CFBundleIdentifier + com.test.webdavdrive.app.extension + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + WebDAVFileProviderExtension + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.1 + CFBundleVersion + 2 + MinimumOSVersion + 16.0 + XSAppIconAssets + Assets.xcassets/AppIcon.appiconset + NSExtension + + NSExtensionAttributes + + NSExtensionPointIdentifier + com.apple.fileprovider-nonui + NSExtensionPrincipalClass + VirtualEngine + NSExtensionFileProviderSupportsEnumeration + + NSExtensionFileProviderDocumentGroup + group.com.test.webdavdrive + + + diff --git a/iOS/WebDAVDrive/WebDAVFileProviderExtension/WebDAVFileProviderExtension.csproj b/iOS/WebDAVDrive/WebDAVFileProviderExtension/WebDAVFileProviderExtension.csproj new file mode 100644 index 0000000..2fe747c --- /dev/null +++ b/iOS/WebDAVDrive/WebDAVFileProviderExtension/WebDAVFileProviderExtension.csproj @@ -0,0 +1,84 @@ + + + net8.0-ios + Library + enable + true + true + 16.0 + True + WebDAVFileProviderExtension + WebDAVFileProviderExtension + + <_ExportSymbolsExplicitly>false + false + false + + --framework=Security --setenv=MONO_GC_PARAMS=nursery-size=512k,soft-heap-limit=8m,major=marksweep + + false + + false + + true + false + + false + + static + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + False + false + false + + + + + false + + false + none + SdkOnly + 12.0 + + + pdbonly + true + bin\Release + + + prompt + 4 + iPhone Developer + Entitlements.plist + Automatic + true + 12.0 + SdkOnly + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iOS/WebDAVDrive/WebDAViOSApp/AppDelegate.cs b/iOS/WebDAVDrive/WebDAViOSApp/AppDelegate.cs new file mode 100644 index 0000000..44dbd6b --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/AppDelegate.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Common.Core; +using FileProvider; +using Foundation; +using ITHit.FileSystem; +using ITHit.FileSystem.Mac; +using UIKit; +using WebDAVCommon; +using WebDAVMacApp; + +namespace WebDAViOSApp +{ + [Register("AppDelegate")] + public class AppDelegate : UIApplicationDelegate + { + private ILogger Logger = new ConsoleLogger("WebDavFileProviderHostApp"); + internal SecureStorage SecureStorage = new SecureStorage(); + internal Dictionary DomainsRemoteStorageMonitor = new Dictionary(); + internal List ServerUrls = new List(); + private readonly SemaphoreSlim monitorsLock = new SemaphoreSlim(1, 1); + + public override UIWindow? Window { get; set; } + + public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) + { + Logger.LogMessage("Starting FinishedLaunching"); + + ServerUrls = Task.Run(async () => await SecureStorage.GetAsync>("WebDAVServerURLs")).Result; + if (ServerUrls == null || ServerUrls.Count == 0) + { + ServerUrls = AppGroupSettings.Settings.Value.WebDAVServerURLs; + + // Save urls to user's settings. + Task.Run(async () => await SecureStorage.SetAsync("WebDAVServerURLs", ServerUrls)).Wait(); + } + + // Start monitors in background so launch is never blocked by network or File Provider calls. + _ = Task.Run(StartRemoteStorageMonitorsAsync); + + // On iOS 13+ the window is created by the SceneDelegate; on earlier versions create it here. + if (Window != null) + { + Window.RootViewController = new UINavigationController(new DriveListViewController(this, ServerUrls)); + Window.MakeKeyAndVisible(); + } + + Logger.LogMessage("Finished FinishedLaunching"); + return true; + } + + /// + /// Registers the File Provider domain and starts the remote storage monitor. + /// + internal async Task MountAsync(string webDAVServerUrl) + { + string domainIdentifier = new Uri(webDAVServerUrl).Host; + + // Save domain's WebDav server url. + await SecureStorage.SetAsync(domainIdentifier, webDAVServerUrl); + + List webDAVServerURLs = (await SecureStorage.GetAsync>("WebDAVServerURLs")) ?? new List(); + if (!webDAVServerURLs.Contains(webDAVServerUrl)) + { + webDAVServerURLs.Add(webDAVServerUrl); + await SecureStorage.SetAsync("WebDAVServerURLs", webDAVServerURLs); + } + + NSFileProviderDomain? domain = await Common.Core.Registrar.RegisterAsync(domainIdentifier, domainIdentifier, Logger); + if (domain == null) + { + return false; + } + + await StartRemoteStorageMonitorAsync(domain, webDAVServerUrl); + return true; + } + + /// + /// Stops the remote storage monitor and unregisters the File Provider domain. + /// + internal async Task UnmountAsync(string webDAVServerUrl) + { + string domainIdentifier = new Uri(webDAVServerUrl).Host; + + if (DomainsRemoteStorageMonitor.TryGetValue(domainIdentifier, out RemoteStorageMonitor monitor)) + { + await monitor.StopAsync(); + monitor.Dispose(); + DomainsRemoteStorageMonitor.Remove(domainIdentifier); + } + + await Common.Core.Registrar.UnregisterAsync(domainIdentifier, Logger); + } + + /// + /// Checks whether the File Provider domain is registered. + /// + internal Task IsMountedAsync(string webDAVServerUrl) + { + string domainIdentifier = new Uri(webDAVServerUrl).Host; + return Common.Core.Registrar.IsRegisteredAsync(domainIdentifier); + } + + /// + /// Starts (or reconnects) monitors for all registered domains. Safe to call repeatedly. + /// + private async Task StartRemoteStorageMonitorsAsync() + { + foreach (string serverUrl in ServerUrls.ToArray()) + { + try + { + string domainIdentifier = new Uri(serverUrl).Host; + if (await Common.Core.Registrar.IsRegisteredAsync(domainIdentifier)) + { + await StartRemoteStorageMonitorAsync(await Common.Core.Registrar.GetDomainAsync(domainIdentifier), serverUrl); + } + } + catch (Exception ex) + { + Logger.LogError("Failed to start remote storage monitor.", serverUrl, null, ex); + } + } + } + + private async Task StartRemoteStorageMonitorAsync(NSFileProviderDomain domain, string webDAVServerUrl) + { + await monitorsLock.WaitAsync(); + try + { + if (DomainsRemoteStorageMonitor.TryGetValue(domain.Identifier, out RemoteStorageMonitor? existing)) + { + // Already listening, nothing to do. Otherwise reconnect (iOS drops sockets while suspended). + if (existing.SyncState != SynchronizationState.Enabled) + { + await existing.StopAsync(); + await existing.StartAsync(); + } + } + else + { + RemoteStorageMonitor remoteStorageMonitor = new RemoteStorageMonitor(domain.Identifier, webDAVServerUrl, + $"ws{(webDAVServerUrl.StartsWith("https:") ? "s" : string.Empty)}://{domain.Identifier}", + NSFileProviderManager.FromDomain(domain), new ConsoleLogger(typeof(RemoteStorageMonitor).Name)); + remoteStorageMonitor.ServerNotifications = new ServerNotifications(domain.Identifier, NSFileProviderManager.FromDomain(domain), remoteStorageMonitor.Logger); + await remoteStorageMonitor.StartAsync(); + DomainsRemoteStorageMonitor.Add(domain.Identifier, remoteStorageMonitor); + } + } + finally + { + monitorsLock.Release(); + } + } + + // iOS suspends the app shortly after it leaves the foreground and kills its sockets, + // so reconnect (which also pulls all missed changes) every time the app becomes active. + // Called from SceneDelegate because UIApplicationDelegate lifecycle callbacks are not used with scenes. + internal void OnAppActive() + { + _ = Task.Run(StartRemoteStorageMonitorsAsync); + } + + // Ask for extra time so in-flight changes can finish before the app is suspended. + internal void OnAppBackground(UIApplication application) + { + nint taskId = 0; + taskId = application.BeginBackgroundTask("WebDAVMonitor", () => application.EndBackgroundTask(taskId)); + _ = Task.Delay(TimeSpan.FromSeconds(25)).ContinueWith(_ => application.EndBackgroundTask(taskId)); + } + + public override void WillTerminate(UIApplication application) + { + foreach (RemoteStorageMonitor remoteStorageMonitor in DomainsRemoteStorageMonitor.Values) + { + remoteStorageMonitor?.StopAsync(); + remoteStorageMonitor?.Dispose(); + } + } + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png new file mode 100644 index 0000000..fbaa7c8 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-1024.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png new file mode 100644 index 0000000..3f78ca1 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png new file mode 100644 index 0000000..2f698cb Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png new file mode 100644 index 0000000..903b830 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png new file mode 100644 index 0000000..08e6b29 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png new file mode 100644 index 0000000..27673a5 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@1x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png new file mode 100644 index 0000000..0afcd5d Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png new file mode 100644 index 0000000..9b72e39 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83.5@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png new file mode 100644 index 0000000..3038dd2 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png new file mode 100644 index 0000000..7618174 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png new file mode 100644 index 0000000..903b830 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png new file mode 100644 index 0000000..2f6303b Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png new file mode 100644 index 0000000..08e6b29 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png new file mode 100644 index 0000000..07b6023 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png new file mode 100644 index 0000000..07b6023 Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@2x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png new file mode 100644 index 0000000..fc448df Binary files /dev/null and b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60@3x.png differ diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..98cc5ef --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,116 @@ +{ + "images": [ + { + "filename": "AppIcon-iphone-20@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "20x20" + }, + { + "filename": "AppIcon-iphone-20@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "20x20" + }, + { + "filename": "AppIcon-iphone-29@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "29x29" + }, + { + "filename": "AppIcon-iphone-29@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "29x29" + }, + { + "filename": "AppIcon-iphone-40@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "40x40" + }, + { + "filename": "AppIcon-iphone-40@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "40x40" + }, + { + "filename": "AppIcon-iphone-60@2x.png", + "idiom": "iphone", + "scale": "2x", + "size": "60x60" + }, + { + "filename": "AppIcon-iphone-60@3x.png", + "idiom": "iphone", + "scale": "3x", + "size": "60x60" + }, + { + "filename": "AppIcon-ipad-20@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "20x20" + }, + { + "filename": "AppIcon-ipad-20@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "20x20" + }, + { + "filename": "AppIcon-ipad-29@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "29x29" + }, + { + "filename": "AppIcon-ipad-29@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "29x29" + }, + { + "filename": "AppIcon-ipad-40@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "40x40" + }, + { + "filename": "AppIcon-ipad-40@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "40x40" + }, + { + "filename": "AppIcon-ipad-76@1x.png", + "idiom": "ipad", + "scale": "1x", + "size": "76x76" + }, + { + "filename": "AppIcon-ipad-76@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "76x76" + }, + { + "filename": "AppIcon-ipad-83.5@2x.png", + "idiom": "ipad", + "scale": "2x", + "size": "83.5x83.5" + }, + { + "filename": "AppIcon-1024.png", + "idiom": "ios-marketing", + "scale": "1x", + "size": "1024x1024" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} \ No newline at end of file diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/Contents.json b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Authentication.cs b/iOS/WebDAVDrive/WebDAViOSApp/Authentication.cs new file mode 100644 index 0000000..c3fd04f --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Authentication.cs @@ -0,0 +1,144 @@ +using System; +using System.Threading.Tasks; +using Common.Core; +using ITHit.FileSystem; +using ITHit.WebDAV.Client; +using ITHit.WebDAV.Client.Exceptions; +using UIKit; +using WebDAVCommon; + +namespace WebDAViOSApp +{ + /// + /// Presents the authentication UI required by a mounted domain, mirroring the + /// macOS container app login dialog. The File Provider extension sets the + /// LoginType / RequireAuthentication flags in the domain secure storage when + /// the server responds with 401 (basic/digest) or a 302 redirect (cookies). + /// + internal static class Authentication + { + private static readonly ILogger logger = new ConsoleLogger(nameof(Authentication)); + + /// + /// Returns the login type ("UserNamePassword" or "Cookies") when the domain + /// requires authentication, otherwise null. + /// + public static async Task GetRequiredLoginTypeAsync(string domainIdentifier) + { + SecureStorage secureStorage = new SecureStorage(domainIdentifier); + return string.IsNullOrEmpty(await secureStorage.GetAsync("RequireAuthentication")) + ? null + : await secureStorage.GetAsync("LoginType"); + } + + /// + /// Presents the appropriate login UI for the domain: a credentials dialog + /// for basic/digest auth, or a web view with the login page for cookies auth. + /// + public static async Task PresentAsync(UIViewController presenter, string domainIdentifier, Action? onSuccess = null) + { + SecureStorage secureStorage = new SecureStorage(domainIdentifier); + string loginType = await secureStorage.GetAsync("LoginType"); + + switch (loginType) + { + case "UserNamePassword": + PresentCredentialsDialog(presenter, secureStorage, domainIdentifier, onSuccess); + break; + + case "Cookies": + // Load the URL that redirected to the login page; fall back to the drive root. + string failedUrl = await secureStorage.GetAsync("CookiesFailedUrl"); + if (string.IsNullOrEmpty(failedUrl)) + { + failedUrl = await secureStorage.GetAsync(domainIdentifier, useDomainIdentifier: false); + } + + var cookiesController = new CookiesAuthViewController(domainIdentifier, failedUrl, onSuccess); + var navigation = new UINavigationController(cookiesController) + { + ModalPresentationStyle = UIModalPresentationStyle.PageSheet + }; + presenter.PresentViewController(navigation, true, null); + break; + } + } + + private static void PresentCredentialsDialog( + UIViewController presenter, + SecureStorage secureStorage, + string domainIdentifier, + Action? onSuccess, + string? errorMessage = null) + { + var alert = UIAlertController.Create( + "Sign In Required", + errorMessage ?? $"Enter your credentials for {domainIdentifier}", + UIAlertControllerStyle.Alert); + + alert.AddTextField(field => + { + field.Placeholder = "User name"; + field.AutocapitalizationType = UITextAutocapitalizationType.None; + field.AutocorrectionType = UITextAutocorrectionType.No; + field.KeyboardType = UIKeyboardType.Default; + }); + alert.AddTextField(field => + { + field.Placeholder = "Password"; + field.SecureTextEntry = true; + }); + + alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); + alert.AddAction(UIAlertAction.Create("Sign In", UIAlertActionStyle.Default, async _ => + { + string userName = alert.TextFields[0].Text?.Trim() ?? string.Empty; + string password = alert.TextFields[1].Text ?? string.Empty; + + if (await ValidateCredentialsAsync(secureStorage, domainIdentifier, userName, password)) + { + onSuccess?.Invoke(); + } + else + { + PresentCredentialsDialog(presenter, secureStorage, domainIdentifier, + onSuccess, "Invalid credentials. Please try again."); + } + })); + + presenter.PresentViewController(alert, true, null); + } + + /// + /// Stores credentials and validates them against the WebDAV server, + /// same as the macOS AuthViewController.ValidateCredentials(). + /// + private static async Task ValidateCredentialsAsync( + SecureStorage secureStorage, string domainIdentifier, string userName, string password) + { + await secureStorage.SetAsync("UserName", userName); + await secureStorage.SetAsync("Password", password); + await secureStorage.SetAsync("UpdateWebdavSession", "true"); + + try + { + using WebDavSession session = await WebDavSessionUtils.GetWebDavSessionAsync(secureStorage); + await session.GetItemAsync(await secureStorage.GetAsync(domainIdentifier, useDomainIdentifier: false), null, null); + return true; + } + catch (WebDavHttpException webDavHttpException) + { + if (webDavHttpException.Status.Code != 401) + { + logger.LogError($"ValidateCredentialsAsync: {webDavHttpException.Message}", ex: webDavHttpException); + } + return false; + } + catch (Exception ex) + { + logger.LogError($"ValidateCredentialsAsync: {ex.Message}", ex: ex); + return false; + } + } + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/CookiesAuthViewController.cs b/iOS/WebDAVDrive/WebDAViOSApp/CookiesAuthViewController.cs new file mode 100644 index 0000000..3fb1fef --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/CookiesAuthViewController.cs @@ -0,0 +1,144 @@ +using System; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using Common.Core; +using Foundation; +using ObjCRuntime; +using UIKit; +using WebDAVCommon; +using WebKit; + +namespace WebDAViOSApp +{ + /// + /// Presents a web view with the server login page and captures the resulting + /// cookies into the domain secure storage, so the File Provider extension can + /// attach them to WebDAV requests. + /// + internal class CookiesAuthViewController : UIViewController, IWKNavigationDelegate + { + private readonly ConsoleLogger logger = new(nameof(CookiesAuthViewController)); + private readonly SecureStorage secureStorage; + private readonly string failedUrl; + private readonly Action? onLoginSuccess; + private WKWebViewConfiguration? webViewConfiguration; + private WKWebView? webView; + private UIActivityIndicatorView? activityIndicator; + + public CookiesAuthViewController(string domainIdentifier, string failedUrl, Action? onLoginSuccess) + { + this.failedUrl = failedUrl; + this.onLoginSuccess = onLoginSuccess; + secureStorage = new SecureStorage(domainIdentifier); + Title = $"Sign In - {domainIdentifier}"; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + webView?.Dispose(); + webView = null; + webViewConfiguration?.Dispose(); + webViewConfiguration = null; + activityIndicator?.Dispose(); + activityIndicator = null; + } + base.Dispose(disposing); + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + + View!.BackgroundColor = UIColor.SystemBackground; + NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, + (s, e) => DismissViewController(true, null)); + + webViewConfiguration = new WKWebViewConfiguration(); + webView = new WKWebView(View.Bounds, webViewConfiguration) + { + TranslatesAutoresizingMaskIntoConstraints = false, + NavigationDelegate = this + }; + activityIndicator = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Large) + { + TranslatesAutoresizingMaskIntoConstraints = false, + HidesWhenStopped = true + }; + + View.AddSubview(webView); + View.AddSubview(activityIndicator); + + UILayoutGuide safeArea = View.SafeAreaLayoutGuide; + NSLayoutConstraint.ActivateConstraints(new[] + { + webView.TopAnchor.ConstraintEqualTo(safeArea.TopAnchor), + webView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor), + webView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor), + webView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor), + activityIndicator.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor), + activityIndicator.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor) + }); + + logger.LogDebug($"CookiesAuthViewController loading {failedUrl}"); + webView.LoadRequest(new NSUrlRequest(new NSUrl(failedUrl))); + activityIndicator.StartAnimating(); + } + + [Export("webView:decidePolicyForNavigationResponse:decisionHandler:")] + public void DecidePolicy( + WKWebView webView, + WKNavigationResponse navigationResponse, + Action decisionHandler) + { + var response = navigationResponse.Response; + logger.LogDebug($"{nameof(DecidePolicy)} url: {response.Url}"); + + if (response is not NSHttpUrlResponse httpUrlResponse || + httpUrlResponse.StatusCode < 200 || httpUrlResponse.StatusCode > 299 || + !httpUrlResponse.Url.ToString().Equals(failedUrl, StringComparison.InvariantCultureIgnoreCase)) + { + decisionHandler?.Invoke(WKNavigationResponsePolicy.Allow); + return; + } + + // The login page redirected back to the WebDAV URL successfully - harvest the cookies. + webViewConfiguration!.WebsiteDataStore.HttpCookieStore.GetAllCookies(cookies => + { + logger.LogDebug("CookiesAuthViewController saving cookies"); + Task.Run(async () => + { + await secureStorage.SetAsync("Cookies", + cookies.Select(c => new Cookie(c.Name, c.Value, c.Path, c.Domain)).ToList()); + await secureStorage.SetAsync("UpdateWebdavSession", "true"); + + InvokeOnMainThread(() => + DismissViewController(true, () => onLoginSuccess?.Invoke())); + }); + }); + decisionHandler?.Invoke(WKNavigationResponsePolicy.Allow); + } + + [Export("webView:didFinishNavigation:")] + public void DidFinishNavigation(WKWebView webView, WKNavigation navigation) + { + activityIndicator?.StopAnimating(); + } + + [Export("webView:didFailNavigation:withError:")] + public void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error) + { + logger.LogDebug($"{nameof(DidFailNavigation)}: {error.LocalizedDescription}"); + activityIndicator?.StopAnimating(); + } + + [Export("webView:didFailProvisionalNavigation:withError:")] + public void DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigation, NSError error) + { + logger.LogDebug($"{nameof(DidFailProvisionalNavigation)}: {error.LocalizedDescription}"); + activityIndicator?.StopAnimating(); + } + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/DriveListViewController.cs b/iOS/WebDAVDrive/WebDAViOSApp/DriveListViewController.cs new file mode 100644 index 0000000..e0ba937 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/DriveListViewController.cs @@ -0,0 +1,405 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Common.Core; +using CoreGraphics; +using Foundation; +using ITHit.FileSystem; +using UIKit; +using WebDAVCommon; + +namespace WebDAViOSApp +{ + /// + /// Lists configured WebDAV server URLs and mounts/unmounts the corresponding + /// File Provider domains. Mounted drives appear in the Files app. + /// Presents the sign-in UI when the server requires authentication. + /// + internal class DriveListViewController : UITableViewController + { + private class DriveState + { + public bool Mounted; + public bool AuthRequired; + } + + private const string CellId = "cell"; + + private readonly AppDelegate appDelegate; + private readonly List serverUrls = new List(); + private readonly Dictionary driveStates = new Dictionary(); + private readonly ILogger logger = new ConsoleLogger(nameof(DriveListViewController)); + + public DriveListViewController(AppDelegate appDelegate, List initialUrls) + : base(UITableViewStyle.InsetGrouped) + { + this.appDelegate = appDelegate; + serverUrls.AddRange(initialUrls ?? new List()); + Title = "WebDAV Drive"; + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + + NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s, e) => ShowAddUrlDialog()); + + RefreshControl = new UIRefreshControl(); + RefreshControl.ValueChanged += (s, e) => RefreshStates(); + + UpdateEmptyView(); + RefreshStates(); + } + + public override void ViewWillAppear(bool animated) + { + base.ViewWillAppear(animated); + if (NavigationController != null) + { + NavigationController.NavigationBar.PrefersLargeTitles = true; + } + RefreshStates(); + } + + public override nint RowsInSection(UITableView tableView, nint section) => serverUrls.Count; + + public override string TitleForHeader(UITableView tableView, nint section) => "Drives"; + + public override string TitleForFooter(UITableView tableView, nint section) + => serverUrls.Count > 0 ? "Tap a drive to mount it in the Files app. Swipe left to remove it." : null!; + + public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) + { + UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellId); + + string url = serverUrls[indexPath.Row]; + driveStates.TryGetValue(url, out DriveState? state); + + var config = UIListContentConfiguration.SubtitleCellConfiguration; + config.Text = new Uri(url).Host; + config.SecondaryText = url; + config.SecondaryTextProperties.Color = UIColor.SecondaryLabel; + config.Image = UIImage.GetSystemImage("externaldrive.fill"); + config.ImageProperties.TintColor = UIColor.SystemBlue; + cell.ContentConfiguration = config; + + cell.AccessoryView = CreateStatusBadge(state); + return cell; + } + + /// + /// Builds the trailing status badge: a colored SF Symbol plus a short status + /// label, similar to OneDrive's per-drive status indicator. + /// + private static UIView CreateStatusBadge(DriveState? state) + { + string text; + UIColor color; + string? symbol = null; + + if (state == null) + { + text = "Connecting"; + color = UIColor.SecondaryLabel; + } + else if (state.AuthRequired) + { + text = "Sign in required"; + color = UIColor.SystemOrange; + symbol = "exclamationmark.circle.fill"; + } + else if (state.Mounted) + { + text = "Connected"; + color = UIColor.SystemGreen; + symbol = "checkmark.circle.fill"; + } + else + { + text = "Not mounted"; + color = UIColor.SecondaryLabel; + } + + var label = new UILabel + { + Text = text, + Font = UIFont.PreferredFootnote, + TextColor = color + }; + + var badge = new UIStackView(new UIView[] { label }) + { + Axis = UILayoutConstraintAxis.Horizontal, + Alignment = UIStackViewAlignment.Center, + Spacing = 4 + }; + + if (symbol != null) + { + var icon = new UIImageView(UIImage.GetSystemImage(symbol)) + { + TintColor = color, + ContentMode = UIViewContentMode.ScaleAspectFit + }; + badge.InsertArrangedSubview(icon, 0); + } + + badge.SizeToFit(); + return badge; + } + + public override void RowSelected(UITableView tableView, NSIndexPath indexPath) + { + string url = serverUrls[indexPath.Row]; + tableView.DeselectRow(indexPath, true); + + driveStates.TryGetValue(url, out DriveState? state); + bool mounted = state?.Mounted ?? false; + bool authRequired = state?.AuthRequired ?? false; + + var sheet = UIAlertController.Create(new Uri(url).Host, url, UIAlertControllerStyle.ActionSheet); + + if (authRequired) + { + sheet.AddAction(UIAlertAction.Create("Sign In", UIAlertActionStyle.Default, _ => ShowLogin(url))); + } + + sheet.AddAction(UIAlertAction.Create(mounted ? "Unmount" : "Mount", UIAlertActionStyle.Default, + action => { _ = ToggleMount(url); })); + + sheet.AddAction(UIAlertAction.Create("Remove Drive", UIAlertActionStyle.Destructive, + action => { _ = RemoveServer(url, indexPath); })); + + sheet.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); + + // Action sheets must be presented from a popover on iPad. + if (sheet.PopoverPresentationController != null) + { + UITableViewCell? cell = tableView.CellAt(indexPath); + sheet.PopoverPresentationController.SourceView = cell as UIView ?? tableView; + sheet.PopoverPresentationController.SourceRect = cell != null ? cell.Bounds : tableView.Bounds; + } + + PresentViewController(sheet, true, null); + } + + public override async void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) + { + if (editingStyle == UITableViewCellEditingStyle.Delete) + { + await RemoveServer(serverUrls[indexPath.Row], indexPath); + } + } + + private async Task RemoveServer(string url, NSIndexPath indexPath) + { + try + { + if (await appDelegate.IsMountedAsync(url)) + { + await appDelegate.UnmountAsync(url); + } + + serverUrls.Remove(url); + driveStates.Remove(url); + await appDelegate.SecureStorage.SetAsync("WebDAVServerURLs", serverUrls); + TableView.DeleteRows(new[] { indexPath }, UITableViewRowAnimation.Automatic); + UpdateEmptyView(); + } + catch (Exception ex) + { + logger.LogError("Delete failed.", ex: ex); + ShowError(ex.Message); + } + } + + private async Task ToggleMount(string url) + { + try + { + if (await appDelegate.IsMountedAsync(url)) + { + await appDelegate.UnmountAsync(url); + } + else + { + bool mounted = await appDelegate.MountAsync(url); + if (!mounted) + { + ShowError($"Failed to register File Provider domain for {url}."); + return; + } + + // The extension only discovers that auth is required after it starts + // and its first request fails (401 / 302 redirect). Poll for the flag + // so the sign-in UI appears on the first mount, not just on remount. + string domainIdentifier = new Uri(url).Host; + if (await WaitForAuthRequirementAsync(domainIdentifier)) + { + ShowLogin(url); + return; + } + } + } + catch (Exception ex) + { + logger.LogError("Mount/Unmount failed.", ex: ex); + ShowError(ex.Message); + } + finally + { + RefreshStates(); + } + } + + /// + /// Polls the domain secure storage until the extension reports that authentication + /// is required or the timeout expires. Also refreshes the row badge along the way. + /// + private async Task WaitForAuthRequirementAsync(string domainIdentifier) + { + var timeout = TimeSpan.FromSeconds(10); + var started = DateTime.UtcNow; + while (DateTime.UtcNow - started < timeout) + { + if (await Authentication.GetRequiredLoginTypeAsync(domainIdentifier) != null) + { + return true; + } + + InvokeOnMainThread(RefreshStates); + await Task.Delay(700); + } + return false; + } + + private void ShowLogin(string url) + { + string domainIdentifier = new Uri(url).Host; + _ = Authentication.PresentAsync(this, domainIdentifier, RefreshStates); + } + + private void RefreshStates() + { + _ = Task.Run(async () => + { + foreach (string url in serverUrls.ToArray()) + { + var state = new DriveState + { + Mounted = await appDelegate.IsMountedAsync(url), + AuthRequired = await Authentication.GetRequiredLoginTypeAsync(new Uri(url).Host) != null + }; + + InvokeOnMainThread(() => + { + driveStates[url] = state; + TableView.ReloadData(); + }); + } + + InvokeOnMainThread(() => RefreshControl?.EndRefreshing()); + }); + } + + /// + /// Shows a friendly empty state when no drives are configured. + /// + private void UpdateEmptyView() + { + if (serverUrls.Count > 0) + { + TableView.BackgroundView = null; + return; + } + + var icon = new UIImageView(UIImage.GetSystemImage("externaldrive")) + { + TintColor = UIColor.TertiaryLabel, + ContentMode = UIViewContentMode.ScaleAspectFit, + TranslatesAutoresizingMaskIntoConstraints = false + }; + + var title = new UILabel + { + Text = "No drives yet", + Font = UIFont.PreferredTitle2, + TextColor = UIColor.Label, + TextAlignment = UITextAlignment.Center + }; + + var subtitle = new UILabel + { + Text = "Tap + to connect a WebDAV server.\nIt will show up in the Files app.", + Font = UIFont.PreferredSubheadline, + TextColor = UIColor.SecondaryLabel, + TextAlignment = UITextAlignment.Center, + Lines = 0 + }; + + var stack = new UIStackView(new UIView[] { icon, title, subtitle }) + { + Axis = UILayoutConstraintAxis.Vertical, + Alignment = UIStackViewAlignment.Center, + Spacing = 12, + TranslatesAutoresizingMaskIntoConstraints = false + }; + + var background = new UIView(); + background.AddSubview(stack); + NSLayoutConstraint.ActivateConstraints(new[] + { + icon.HeightAnchor.ConstraintEqualTo(72), + icon.WidthAnchor.ConstraintEqualTo(72), + stack.CenterXAnchor.ConstraintEqualTo(background.CenterXAnchor), + stack.CenterYAnchor.ConstraintEqualTo(background.CenterYAnchor, -60), + stack.LeadingAnchor.ConstraintGreaterThanOrEqualTo(background.LeadingAnchor, 32), + stack.TrailingAnchor.ConstraintLessThanOrEqualTo(background.TrailingAnchor, -32) + }); + + TableView.BackgroundView = background; + } + + private void ShowAddUrlDialog() + { + var alert = UIAlertController.Create("Add WebDAV Server", "e.g. https://webdavserver.net/User123456", UIAlertControllerStyle.Alert); + alert.AddTextField(field => + { + field.Placeholder = "https://server/dav/"; + field.KeyboardType = UIKeyboardType.Url; + field.AutocapitalizationType = UITextAutocapitalizationType.None; + field.AutocorrectionType = UITextAutocorrectionType.No; + }); + alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); + alert.AddAction(UIAlertAction.Create("Add", UIAlertActionStyle.Default, async _action => + { + string? url = alert.TextFields[0].Text?.Trim(); + if (string.IsNullOrEmpty(url) || !Uri.TryCreate(url, UriKind.Absolute, out Uri? _)) + { + return; + } + + if (!url.EndsWith('/')) + { + url += "/"; + } + + serverUrls.Add(url); + await appDelegate.SecureStorage.SetAsync("WebDAVServerURLs", serverUrls); + UpdateEmptyView(); + RefreshStates(); + })); + PresentViewController(alert, true, null); + } + + private void ShowError(string message) + { + InvokeOnMainThread(() => + { + var alert = UIAlertController.Create("Error", message, UIAlertControllerStyle.Alert); + alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); + PresentViewController(alert, true, null); + }); + } + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Entitlements.plist b/iOS/WebDAVDrive/WebDAViOSApp/Entitlements.plist new file mode 100644 index 0000000..501890b --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Entitlements.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.com.test.webdavdrive + + + diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Info.plist b/iOS/WebDAVDrive/WebDAViOSApp/Info.plist new file mode 100644 index 0000000..8d299d2 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Info.plist @@ -0,0 +1,58 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + WebDAV Drive + CFBundleIdentifier + com.test.webdavdrive.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + WebDAV Drive + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.1 + CFBundleVersion + 2 + MinimumOSVersion + 16.0 + XSAppIconAssets + Assets.xcassets/AppIcon.appiconset + UILaunchScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + + + + + + diff --git a/iOS/WebDAVDrive/WebDAViOSApp/Main.cs b/iOS/WebDAVDrive/WebDAViOSApp/Main.cs new file mode 100644 index 0000000..3aea157 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/Main.cs @@ -0,0 +1,6 @@ +using WebDAViOSApp; + +// Keep the scene delegate class reachable so the AOT compiler does not strip it. +_ = typeof(SceneDelegate).FullName; + +UIApplication.Main(args, null, typeof(AppDelegate)); diff --git a/iOS/WebDAVDrive/WebDAViOSApp/SceneDelegate.cs b/iOS/WebDAVDrive/WebDAViOSApp/SceneDelegate.cs new file mode 100644 index 0000000..6b7d3b6 --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/SceneDelegate.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using Foundation; +using ObjCRuntime; +using UIKit; + +namespace WebDAViOSApp +{ + [Register("SceneDelegate")] + [Preserve(AllMembers = true)] + public class SceneDelegate : UIResponder, IUISceneDelegate, IUIWindowSceneDelegate + { + [Export("window")] + public UIWindow? Window { get; set; } + + [Export("scene:willConnectToSession:options:")] + public void WillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions) + { + if (scene is not UIWindowScene windowScene) + { + return; + } + + Window = new UIWindow(windowScene); + + if (UIApplication.SharedApplication.Delegate is AppDelegate appDelegate) + { + Window.RootViewController = new UINavigationController(new DriveListViewController(appDelegate, appDelegate.ServerUrls)); + } + else + { + Window.RootViewController = new UIViewController(); + } + + Window.MakeKeyAndVisible(); + } + + [Export("sceneDidBecomeActive:")] + public void DidBecomeActive(UIScene scene) + { + (UIApplication.SharedApplication.Delegate as AppDelegate)?.OnAppActive(); + } + + [Export("sceneDidEnterBackground:")] + public void DidEnterBackground(UIScene scene) + { + (UIApplication.SharedApplication.Delegate as AppDelegate)?.OnAppBackground(UIApplication.SharedApplication); + } + } +} diff --git a/iOS/WebDAVDrive/WebDAViOSApp/WebDAViOSApp.csproj b/iOS/WebDAVDrive/WebDAViOSApp/WebDAViOSApp.csproj new file mode 100644 index 0000000..173e8fd --- /dev/null +++ b/iOS/WebDAVDrive/WebDAViOSApp/WebDAViOSApp.csproj @@ -0,0 +1,97 @@ + + + net8.0-ios + Exe + enable + true + true + 16.0 + WebDAViOSApp + WebDAV Drive + + --framework=Security + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + + + false + false + none + None + 12.0 + + + pdbonly + true + bin\Release + + + prompt + 4 + + iPhone Developer + Entitlements.plist + Automatic + true + 12.0 + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_AppexSource Include="..\WebDAVFileProviderExtension\bin\$(Configuration)\WebDAVFileProviderExtension.appex" /> + + + + + + + + + + \ No newline at end of file diff --git a/iOS/WebDAVDrive/build-device.sh b/iOS/WebDAVDrive/build-device.sh new file mode 100644 index 0000000..7d08732 --- /dev/null +++ b/iOS/WebDAVDrive/build-device.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +# Build and deploy the WebDAV Drive iOS sample to a connected device. +# This requires an Apple Developer account, a valid iPhone Developer certificate, +# and a development provisioning profile that includes the App Group +# group.com.test.webdavdrive for both com.test.webdavdrive.app and com.test.webdavdrive.app.extension. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT="$SCRIPT_DIR/WebDAViOSApp/WebDAViOSApp.csproj" +CONFIG="${CONFIG:-Release}" +RUNTIME_ID="${RUNTIME_ID:-ios-arm64}" +CODESIGN_KEY="${CODESIGN_KEY:-iPhone Developer}" +CODESIGN_PROVISION="${CODESIGN_PROVISION:-Automatic}" + +if [ -z "${TEAM_ID:-}" ]; then + echo "Please set TEAM_ID to your Apple Developer Team ID, e.g.:" + echo " export TEAM_ID=ABCD123456" + echo "If you do not know your Team ID, run: security find-identity -v -p codesigning" + exit 1 +fi + +echo "Building WebDAV Drive for device ($RUNTIME_ID) in $CONFIG configuration..." + +# Incremental device builds can keep stale *.aotdata.* files that no longer match the +# rebuilt assemblies, which makes the app abort on launch ("Failed to load AOT module"). +# Always start from clean outputs; set CLEAN=false to skip. +if [ "${CLEAN:-true}" = "true" ]; then + rm -rf "$SCRIPT_DIR/WebDAViOSApp/bin/$CONFIG/net8.0-ios/$RUNTIME_ID" \ + "$SCRIPT_DIR/WebDAViOSApp/obj/$CONFIG/net8.0-ios/$RUNTIME_ID" \ + "$SCRIPT_DIR/WebDAVFileProviderExtension/bin/$CONFIG" \ + "$SCRIPT_DIR/WebDAVFileProviderExtension/obj/$CONFIG" +fi + +dotnet build "$PROJECT" \ + -c "$CONFIG" \ + -p:RuntimeIdentifier="$RUNTIME_ID" \ + -p:CodesignKey="$CODESIGN_KEY" \ + -p:CodesignProvision="$CODESIGN_PROVISION" \ + -p:CodesignRequireProvisioningProfile=true \ + "$@" + +APP_BUNDLE="$SCRIPT_DIR/WebDAViOSApp/bin/$CONFIG/net8.0-ios/$RUNTIME_ID/WebDAV Drive.app" + +if [ ! -d "$APP_BUNDLE" ]; then + echo "App bundle not found at: $APP_BUNDLE" + exit 1 +fi + +# --- Re-sign embedded extension + app for device --------------------------- +# The app csproj embeds the .appex AFTER the .NET build signs the app (the +# EmbedFileProviderExtension target runs AfterTargets="Build"), so on device the +# embedded extension ends up with no code signature. Re-sign the extension (and +# then re-seal the app) using the developer identity + installed profiles. +APPEX="$APP_BUNDLE/PlugIns/WebDAVFileProviderExtension.appex" +APP_BUNDLE_ID="${APP_BUNDLE_ID:-com.test.webdavdrive.app}" +EXT_BUNDLE_ID="${EXT_BUNDLE_ID:-com.test.webdavdrive.app.extension}" + +# Provisioning profiles downloaded by fastlane (sigh) into this directory. +APP_PROFILE="${APP_PROFILE:-$(ls "$SCRIPT_DIR"/*"${APP_BUNDLE_ID}".mobileprovision 2>/dev/null | head -1)}" +EXT_PROFILE="${EXT_PROFILE:-$(ls "$SCRIPT_DIR"/*"${EXT_BUNDLE_ID}".mobileprovision 2>/dev/null | head -1)}" + +# Developer signing identity (SHA-1). Overridable via CODESIGN_IDENTITY. +SIGN_ID="${CODESIGN_IDENTITY:-$(security find-identity -v -p codesigning \ + | grep -E "Apple Development|iPhone Developer" | head -1 | awk '{print $2}')}" + +extract_entitlements() { + # $1 = .mobileprovision, $2 = output entitlements plist + security cms -D -i "$1" > "$2.full" 2>/dev/null + /usr/libexec/PlistBuddy -x -c 'Print :Entitlements' "$2.full" > "$2" + rm -f "$2.full" +} + +if [ -d "$APPEX" ] && [ -n "$SIGN_ID" ] && [ -n "$APP_PROFILE" ] && [ -n "$EXT_PROFILE" ]; then + echo "Re-signing embedded extension and app for device (identity $SIGN_ID)..." + echo " app profile: $APP_PROFILE" + echo " ext profile: $EXT_PROFILE" + + cp "$EXT_PROFILE" "$APPEX/embedded.mobileprovision" + cp "$APP_PROFILE" "$APP_BUNDLE/embedded.mobileprovision" + + extract_entitlements "$EXT_PROFILE" "/tmp/webdav_ext_entitlements.plist" + extract_entitlements "$APP_PROFILE" "/tmp/webdav_app_entitlements.plist" + + # Sign nested native code inside the extension first, then the extension. + find "$APPEX" -type f -name '*.dylib' -exec \ + codesign --force --sign "$SIGN_ID" --timestamp=none {} \; + codesign --force --sign "$SIGN_ID" --timestamp=none --generate-entitlement-der \ + --entitlements "/tmp/webdav_ext_entitlements.plist" "$APPEX" + + # Re-seal the app so its signature covers the freshly signed extension. + codesign --force --sign "$SIGN_ID" --timestamp=none --generate-entitlement-der \ + --entitlements "/tmp/webdav_app_entitlements.plist" "$APP_BUNDLE" + + echo "Verifying signatures..." + codesign --verify --deep --strict --verbose=2 "$APP_BUNDLE" || true +else + echo "WARNING: skipping device re-sign (missing identity or profiles)." + echo " SIGN_ID=${SIGN_ID:-}" + echo " APP_PROFILE=${APP_PROFILE:-}" + echo " EXT_PROFILE=${EXT_PROFILE:-}" +fi + +# Try to deploy with devicectl (macOS 14+). Fall back to just printing the path otherwise. +if command -v xcrun >/dev/null 2>&1 && xcrun --find devicectl >/dev/null 2>&1; then + # devicectl requires a target device. Use DEVICE_ID if provided, otherwise + # auto-pick the first connected physical device. + if [ -z "${DEVICE_ID:-}" ]; then + # Pick the identifier (UUID) of the first connected iPhone/iPad. + DEVICE_ID="$(xcrun devicectl list devices 2>/dev/null \ + | grep -iE 'iPhone|iPad' \ + | grep -oE '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}' \ + | head -1)" + fi + + if [ -z "${DEVICE_ID:-}" ]; then + echo "No connected device found. Connect/unlock your device (and trust this Mac), then:" + echo " xcrun devicectl list devices" + echo " DEVICE_ID= ./build-device.sh" + echo "Or install manually:" + echo " $APP_BUNDLE" + exit 1 + fi + + echo "Installing $APP_BUNDLE on device $DEVICE_ID..." + xcrun devicectl device install app --device "$DEVICE_ID" "$APP_BUNDLE" + echo "Done. Open the WebDAV Drive app on the device and tap the server URL to mount it." +else + echo "Build complete. Install manually with Xcode or a tool such as ios-deploy:" + echo " $APP_BUNDLE" +fi diff --git a/iOS/WebDAVDrive/fastlane/Appfile b/iOS/WebDAVDrive/fastlane/Appfile new file mode 100644 index 0000000..a6cab25 --- /dev/null +++ b/iOS/WebDAVDrive/fastlane/Appfile @@ -0,0 +1,17 @@ +# fastlane Appfile for the WebDAV Drive iOS sample. +# +# Values can be set here or overridden with environment variables so the same +# config works on a dev machine and in CI: +# FASTLANE_USER -> your Apple ID email (login) +# FASTLANE_TEAM_ID -> your 10-character Apple Developer Team ID +# +# The container app identifier is the "primary" app id. The File Provider +# extension id and the App Group are referenced from the Fastfile. + +app_identifier ENV["APP_IDENTIFIER"] || "com.test.webdavdrive.app" + +# Apple ID used to log in to the Apple Developer portal. +apple_id ENV["FASTLANE_USER"] + +# Apple Developer Team ID (Developer portal, not App Store Connect team name). +team_id ENV["FASTLANE_TEAM_ID"] diff --git a/iOS/WebDAVDrive/fastlane/Fastfile b/iOS/WebDAVDrive/fastlane/Fastfile new file mode 100644 index 0000000..6272632 --- /dev/null +++ b/iOS/WebDAVDrive/fastlane/Fastfile @@ -0,0 +1,168 @@ +# fastlane configuration for the WebDAV Drive iOS sample. +# +# This file automates everything needed to run the File Provider extension on a +# real device: +# * creates (or reuses) the two App IDs +# * creates (or reuses) the shared App Group and associates it with both IDs +# * creates (or reuses) a development signing certificate +# * creates (or edits) a development provisioning profile for each App ID +# * builds and deploys the app with build-device.sh +# +# Authentication: Apple ID + password (interactive 2FA). +# export FASTLANE_USER="you@example.com" +# export FASTLANE_TEAM_ID="ABCD123456" +# The password is read from FASTLANE_PASSWORD if set, otherwise fastlane prompts. +# A 2FA code is requested the first time; set FASTLANE_SESSION to reuse a session. +# +# Common commands: +# fastlane signing # app ids + app group + certificate + profiles +# fastlane profiles FORCE:true # regenerate/edit existing profiles +# fastlane build # build + deploy to the connected device +# fastlane release # signing, then build + deploy + +# --------------------------------------------------------------------------- +# Identifiers (must match Info.plist / Entitlements.plist in the projects). +# --------------------------------------------------------------------------- +APP_ID = "com.test.webdavdrive.app" +EXT_ID = "com.test.webdavdrive.app.extension" +APP_GROUP = "group.com.test.webdavdrive" + +APP_NAME = "WebDAV Drive" +EXT_NAME = "WebDAV Drive File Provider" +GROUP_NAME = "WebDAV VFS App Group" + +APP_PROFILE = "WebDAV Drive Development" +EXT_PROFILE = "WebDAV Drive Extension Development" + +# true when the user passes FORCE:true (e.g. `fastlane profiles FORCE:true`) +# or sets the FORCE env var. Forces profiles to be regenerated / edited. +def force?(options) + options[:FORCE].to_s == "true" || ENV["FORCE"].to_s == "true" +end + +PROJECT_DIR = File.expand_path("..", __dir__) + +# True when a profile already downloaded into PROJECT_DIR is still usable, so +# the Developer portal does not need to be contacted (sigh would otherwise +# create a brand new profile whenever it cannot match one to a local certificate). +def local_profile_ok?(identifier) + require "cfpropertylist" + require "openssl" + + path = Dir[File.join(PROJECT_DIR, "*#{identifier}.mobileprovision")].max_by { |f| File.mtime(f) } + return false unless path + + xml = `security cms -D -i "#{path}" 2>/dev/null` + return false if xml.empty? + + plist = CFPropertyList.native_types(CFPropertyList::List.new(data: xml).value) + return false if plist["ExpirationDate"].to_time <= Time.now + return false unless plist.dig("Entitlements", "application-identifier").to_s.end_with?(".#{identifier}") + return false unless Array(plist.dig("Entitlements", "com.apple.security.application-groups")).include?(APP_GROUP) + + # At least one certificate in the profile must be installed in the keychain. + installed = `security find-identity -v -p codesigning`.scan(/\b[0-9A-F]{40}\b/) + profile_certs = Array(plist["DeveloperCertificates"]).map { |c| OpenSSL::Digest::SHA1.hexdigest(c.to_s).upcase } + (installed & profile_certs).any? +rescue StandardError => e + UI.important("Could not inspect local profile for #{identifier}: #{e.message}") + false +end + +default_platform(:ios) + +platform :ios do + desc "Create or reuse both App IDs with the App Group capability enabled" + lane :app_ids do + [APP_ID, EXT_ID].each do |identifier| + name = identifier == APP_ID ? APP_NAME : EXT_NAME + # produce is idempotent: it registers the App ID if missing and leaves it + # untouched if it already exists. skip_itc avoids creating an App Store + # Connect record we don't need for a dev-only sample. + produce( + app_identifier: identifier, + app_name: name, + skip_itc: true, + enable_services: { + app_group: "on" + } + ) + end + end + + desc "Create or reuse the shared App Group and associate it with both App IDs" + lane :app_group do + # `produce group` / `associate_group` have no Ruby action, so call the CLI. + # They return a non-zero code if the group already exists, which is fine. + sh("fastlane produce group -g #{APP_GROUP} -n '#{GROUP_NAME}' || true") + sh("fastlane produce associate_group -a #{APP_ID} #{APP_GROUP} || true") + sh("fastlane produce associate_group -a #{EXT_ID} #{APP_GROUP} || true") + end + + desc "Create or reuse a development signing certificate" + lane :certificates do + # get_certificates (alias `cert`) reuses a valid installed certificate and + # only creates a new one when none is available. + get_certificates(development: true) + end + + desc "Register a new device in the Apple Developer Portal" + lane :add_device do |options| + name = options[:NAME] || ENV["DEVICE_NAME"] + udid = options[:UDID] || ENV["DEVICE_UDID"] + + UI.user_error!("Device name required. Pass NAME: or set DEVICE_NAME.") if name.to_s.empty? + UI.user_error!("Device UDID required. Pass UDID: or set DEVICE_UDID.") if udid.to_s.empty? + + register_device( + name: name, + udid: udid + ) + end + + desc "Create or edit a development provisioning profile for each App ID" + lane :profiles do |options| + regenerate = force?(options) + + # get_provisioning_profile (alias `sigh`) downloads the existing profile by + # default, or regenerates it (picking up new devices / capabilities) when + # force is true — this is the "edit if existing" behaviour. + [[APP_ID, APP_PROFILE], [EXT_ID, EXT_PROFILE]].each do |identifier, name| + if !regenerate && local_profile_ok?(identifier) + UI.success("Reusing valid local profile for #{identifier} (pass FORCE:true to regenerate)") + next + end + + get_provisioning_profile( + app_identifier: identifier, + provisioning_name: name, + development: true, + force: regenerate + ) + end + end + + desc "Full signing setup: App IDs, App Group, certificate and profiles" + lane :signing do |options| + app_ids + app_group + certificates + profiles(options) + end + + desc "Build and deploy to the connected device via build-device.sh" + lane :build do + team = CredentialsManager::AppfileConfig.try_fetch_value(:team_id) + UI.user_error!("Team ID not set. Export FASTLANE_TEAM_ID or edit fastlane/Appfile.") if team.to_s.empty? + + # build-device.sh signs with 'Automatic' provisioning, which on .NET iOS + # matches each project's bundle id against the profiles fastlane installed. + sh("cd .. && TEAM_ID=#{team} ./build-device.sh") + end + + desc "Set up signing, then build and deploy" + lane :release do |options| + signing(options) + build + end +end diff --git a/iOS/WebDAVDrive/fastlane/README.md b/iOS/WebDAVDrive/fastlane/README.md new file mode 100644 index 0000000..bb81be0 --- /dev/null +++ b/iOS/WebDAVDrive/fastlane/README.md @@ -0,0 +1,88 @@ +fastlane documentation +---- + +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +```sh +xcode-select --install +``` + +For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) + +# Available Actions + +## iOS + +### ios app_ids + +```sh +[bundle exec] fastlane ios app_ids +``` + +Create or reuse both App IDs with the App Group capability enabled + +### ios app_group + +```sh +[bundle exec] fastlane ios app_group +``` + +Create or reuse the shared App Group and associate it with both App IDs + +### ios certificates + +```sh +[bundle exec] fastlane ios certificates +``` + +Create or reuse a development signing certificate + +### ios add_device + +```sh +[bundle exec] fastlane ios add_device +``` + +Register a new device in the Apple Developer Portal + +### ios profiles + +```sh +[bundle exec] fastlane ios profiles +``` + +Create or edit a development provisioning profile for each App ID + +### ios signing + +```sh +[bundle exec] fastlane ios signing +``` + +Full signing setup: App IDs, App Group, certificate and profiles + +### ios build + +```sh +[bundle exec] fastlane ios build +``` + +Build and deploy to the connected device via build-device.sh + +### ios release + +```sh +[bundle exec] fastlane ios release +``` + +Set up signing, then build and deploy + +---- + +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. + +More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). + +The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools). diff --git a/iOS/WebDAVDrive/setup-signing.sh b/iOS/WebDAVDrive/setup-signing.sh new file mode 100644 index 0000000..a3fd7af --- /dev/null +++ b/iOS/WebDAVDrive/setup-signing.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# One-shot signing setup + optional build for the WebDAV Drive iOS sample. +# +# It drives fastlane (see fastlane/Fastfile) to create — or reuse/edit if they +# already exist — the App IDs, App Group, development certificate and +# provisioning profiles, then optionally builds and deploys to a device. +# +# Usage: +# export FASTLANE_USER="you@example.com" # your Apple ID +# export FASTLANE_TEAM_ID="ABCD123456" # your 10-char Team ID +# ./setup-signing.sh # signing setup only +# ./setup-signing.sh --build # signing setup + build & deploy +# ./setup-signing.sh --force # regenerate/edit existing profiles +# ./setup-signing.sh --build --force # do both +# +# Optional: +# export FASTLANE_PASSWORD="..." # avoids the interactive password prompt +# export FASTLANE_SESSION="..." # reuse a 2FA session (see `fastlane spaceauth`) + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR" + +DO_BUILD=false +FORCE=false +for arg in "$@"; do + case "$arg" in + --build) DO_BUILD=true ;; + --force) FORCE=true ;; + *) echo "Unknown option: $arg"; exit 1 ;; + esac +done + +# --- Preconditions --------------------------------------------------------- +if ! command -v fastlane >/dev/null 2>&1; then + echo "fastlane is not installed. Install it with one of:" + echo " brew install fastlane" + echo " gem install fastlane" + exit 1 +fi + +if [ -z "${FASTLANE_USER:-}" ]; then + echo "Please set FASTLANE_USER to your Apple ID email, e.g.:" + echo " export FASTLANE_USER=you@example.com" + exit 1 +fi + +if [ -z "${FASTLANE_TEAM_ID:-}" ]; then + echo "Please set FASTLANE_TEAM_ID to your 10-char Apple Developer Team ID, e.g.:" + echo " export FASTLANE_TEAM_ID=ABCD123456" + echo "Find it with: security find-identity -v -p codesigning" + exit 1 +fi + +# fastlane (cert / sigh) needs full Xcode, not just the Command Line Tools. +# If the active developer dir is the CLT, point DEVELOPER_DIR at Xcode so +# xcode-select/xcrun resolve to Xcode for this run without needing sudo. +XCODE_DIR="/Applications/Xcode.app/Contents/Developer" +if [ -z "${DEVELOPER_DIR:-}" ] && [ -d "$XCODE_DIR" ]; then + case "$(xcode-select -p 2>/dev/null)" in + *CommandLineTools*|"") export DEVELOPER_DIR="$XCODE_DIR" ;; + esac +fi + +if [ -n "${DEVELOPER_DIR:-}" ]; then + echo "Using Xcode at: $DEVELOPER_DIR" +elif ! xcrun --find xcodebuild >/dev/null 2>&1; then + echo "Could not locate Xcode. Install Xcode and either:" + echo " export DEVELOPER_DIR=$XCODE_DIR" + echo " or: sudo xcode-select --switch $XCODE_DIR" + exit 1 +fi + +# --- Run ------------------------------------------------------------------- +# Pass "FORCE:true" to fastlane only when --force was given. The +# "${arr[@]:-}" guard keeps this working under `set -u` on bash 3.2 (macOS), +# where expanding an empty array would otherwise fail with "unbound variable". +FASTLANE_ARGS=() +$FORCE && FASTLANE_ARGS+=("FORCE:true") + +if $DO_BUILD; then + echo "Setting up signing and deploying to the connected device..." + fastlane release ${FASTLANE_ARGS[@]:-} +else + echo "Setting up signing (App IDs, App Group, certificate, profiles)..." + fastlane signing ${FASTLANE_ARGS[@]:-} + echo + echo "Signing setup complete. To build and deploy, run:" + echo " ./setup-signing.sh --build" + echo "or directly:" + echo " TEAM_ID=$FASTLANE_TEAM_ID ./build-device.sh" +fi diff --git a/iOS/global.json b/iOS/global.json new file mode 100644 index 0000000..0a1a4c5 --- /dev/null +++ b/iOS/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.305", + "rollForward": "latestFeature" + } +} diff --git a/iOS/setup.md b/iOS/setup.md new file mode 100644 index 0000000..ee8306d --- /dev/null +++ b/iOS/setup.md @@ -0,0 +1,16 @@ +cd /Users/myroslava/Documents/GitHub/fuse/Sources/Samples/iOS/WebDAVDrive + +export FASTLANE_USER="you@example.com" # your Apple ID +export FASTLANE_TEAM_ID="ABCD123456" # 10-char Team ID + +# 1) Install fastlane if needed +brew install fastlane # or: gem install fastlane + +# 2) Signing setup only (App IDs + group + cert + profiles) +./setup-signing.sh + +# 3) Edit/regenerate existing profiles (e.g. after adding a device) +./setup-signing.sh --force + +# 4) Full flow: signing setup + build & deploy to the connected device +./setup-signing.sh --build \ No newline at end of file diff --git a/macOS/.vscode/extensions.json b/macOS/.vscode/extensions.json new file mode 100644 index 0000000..9845e9d --- /dev/null +++ b/macOS/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-dotnettools.csdevkit", + "ms-dotnettools.csharp" + ] +} diff --git a/macOS/.vscode/launch.json b/macOS/.vscode/launch.json new file mode 100644 index 0000000..1cc542d --- /dev/null +++ b/macOS/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Virtual Filesystem Sample", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/VirtualFileSystem/VirtualFileSystemMacApp/bin/Debug/net10.0-macos/osx-x64/Virtual Filesystem Sample.app/Contents/MacOS/Virtual Filesystem Sample", + "args": [], + "cwd": "${workspaceFolder}/VirtualFileSystem/VirtualFileSystemMacApp", + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": "Launch WebDAV Drive", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/WebDAVDrive/WebDAVMacApp/bin/Debug/net10.0-macos/osx-x64/WebDAV Drive.app/Contents/MacOS/WebDAV Drive", + "args": [], + "cwd": "${workspaceFolder}/WebDAVDrive/WebDAVMacApp", + "console": "internalConsole", + "stopAtEntry": false + } + ] +} diff --git a/macOS/.vscode/tasks.json b/macOS/.vscode/tasks.json new file mode 100644 index 0000000..aee87e4 --- /dev/null +++ b/macOS/.vscode/tasks.json @@ -0,0 +1,32 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "UserFileSystemSamplesMac.sln" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$msCompile" + }, + { + "label": "build-release", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "UserFileSystemSamplesMac.sln", + "-c", + "Release" + ], + "group": "build", + "problemMatcher": "$msCompile" + } + ] +} diff --git a/macOS/Common/Core/Common.Core.csproj b/macOS/Common/Core/Common.Core.csproj index fa9e5fe..d87ef9e 100644 --- a/macOS/Common/Core/Common.Core.csproj +++ b/macOS/Common/Core/Common.Core.csproj @@ -1,10 +1,10 @@ - net8.0-macos + net10.0-macos Library enable true - 10.15 + 12.0 false false @@ -19,6 +19,6 @@ None
- + -
+
\ No newline at end of file diff --git a/macOS/Common/Core/Common.Core.iOS.csproj b/macOS/Common/Core/Common.Core.iOS.csproj new file mode 100644 index 0000000..261648c --- /dev/null +++ b/macOS/Common/Core/Common.Core.iOS.csproj @@ -0,0 +1,31 @@ + + + + net8.0-ios + Library + enable + true + 16.0 + false + false + 12.0 + + + true + full + false + bin-ios\Debug + DEBUG; + + + true + bin-ios\Release + + + + + \ No newline at end of file diff --git a/macOS/Common/Core/ConsoleLogger.cs b/macOS/Common/Core/ConsoleLogger.cs index 3b52f1b..d382037 100644 --- a/macOS/Common/Core/ConsoleLogger.cs +++ b/macOS/Common/Core/ConsoleLogger.cs @@ -11,15 +11,22 @@ namespace Common.Core { public static class NSLogHelper { - [DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")] - extern static void NSLog(IntPtr format, [MarshalAs(UnmanagedType.LPStr)] string s); + // NSLog(NSString *format, ...) is a C variadic function. Passing a + // separate vararg (e.g. "%s" + value) breaks on ARM64 (devices), where + // variadic args are passed on the stack rather than in registers, which + // a fixed-signature P/Invoke cannot satisfy. Instead we format the whole + // message in managed code and pass it as the format itself with no + // varargs (escaping '%'), which is ABI-safe on both ARM64 and x86_64. + [DllImport("/System/Library/Frameworks/Foundation.framework/Foundation", EntryPoint = "NSLog")] + extern static void NSLogInternal(IntPtr format); public static void NSLog(string format, params object[] args) { - var fmt = CFString.CreateNative("%s"); var val = (args is null || args.Length == 0) ? format : string.Format(format, args); - NSLog(fmt, val); + // No variadic args are passed, so escape '%' to avoid format parsing. + var fmt = CFString.CreateNative(val.Replace("%", "%%")); + NSLogInternal(fmt); NSString.ReleaseNative(fmt); } } diff --git a/macOS/Common/Core/Directory.Build.props b/macOS/Common/Core/Directory.Build.props new file mode 100644 index 0000000..3ca5ddc --- /dev/null +++ b/macOS/Common/Core/Directory.Build.props @@ -0,0 +1,7 @@ + + + obj-ios\ + bin-ios\ + $(DefaultItemExcludes);obj\**;bin\**;obj-ios\**;bin-ios\** + + diff --git a/macOS/Common/DebugSigning.targets b/macOS/Common/DebugSigning.targets new file mode 100644 index 0000000..cfe157a --- /dev/null +++ b/macOS/Common/DebugSigning.targets @@ -0,0 +1,29 @@ + + + + + + + $(DebugSigningIdentity) + $(DebugSigningIdentity) + + + + + + <_DebugSigningDirectory>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)debug-signing', '$(MSBuildProjectDirectory)')) + $(_DebugSigningDirectory)/Entitlements.plist + + + + + + $(_DebugSigningDirectory)/Info.plist + $(DebugSigningEntitlements) + + + + + + + diff --git a/macOS/Common/prepare-debug-signing.sh b/macOS/Common/prepare-debug-signing.sh new file mode 100644 index 0000000..55e9b97 --- /dev/null +++ b/macOS/Common/prepare-debug-signing.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +identity="$1" +manifest="$2" +entitlements="$3" +output_dir="$4" +mkdir -p "$output_dir" +probe_dir="$(mktemp -d "$output_dir/probe.XXXXXX")" +trap 'rm -rf "$probe_dir"' EXIT +cp /usr/bin/true "$probe_dir/signing-probe" +if ! signing_output="$(/usr/bin/codesign --force --sign "$identity" --timestamp=none "$probe_dir/signing-probe" 2>&1)"; then + printf '%s\n' "$signing_output" >&2 + exit 1 +fi +team_id="$(/usr/bin/codesign -dvv "$probe_dir/signing-probe" 2>&1 | /usr/bin/awk -F= '/^TeamIdentifier=/ { print $2 }')" +if [[ ! "$team_id" =~ ^[A-Z0-9]{10}$ ]]; then + echo "The selected development identity does not have a valid Apple Team ID." >&2 + exit 1 +fi + +/usr/bin/sed "s/YOURTEAMID/$team_id/g" "$entitlements" | /usr/bin/perl -pe 's/\r\n/\n/g' > "$output_dir/Entitlements.plist.tmp" +/usr/bin/sed "s/YOURTEAMID/$team_id/g" "$manifest" > "$output_dir/Info.plist.tmp" +app_group="$(/usr/libexec/PlistBuddy -c 'Print :com.apple.security.application-groups:0' "$output_dir/Entitlements.plist.tmp")" +if ! /usr/libexec/PlistBuddy -c "Set :SampleAppGroupId $app_group" "$output_dir/Info.plist.tmp" 2>/dev/null; then + /usr/libexec/PlistBuddy -c "Add :SampleAppGroupId string $app_group" "$output_dir/Info.plist.tmp" +fi +for name in Info.plist Entitlements.plist; do + if cmp -s "$output_dir/$name.tmp" "$output_dir/$name"; then + rm "$output_dir/$name.tmp" + else + mv "$output_dir/$name.tmp" "$output_dir/$name" + fi +done +printf '%s\n' "$team_id" diff --git a/macOS/Common/select-debug-identity.sh b/macOS/Common/select-debug-identity.sh new file mode 100644 index 0000000..5a0258d --- /dev/null +++ b/macOS/Common/select-debug-identity.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +identity="$(/usr/bin/security find-identity -v -p codesigning | /usr/bin/awk '/"Apple Development:|"Mac Developer:|"iPhone Developer:/ && !selected { selected = $2 } END { print selected }')" +if [ -z "$identity" ]; then + echo "No valid Apple development signing identity found. Install a development certificate and its private key in Keychain before building the macOS samples." >&2 + exit 1 +fi +printf '%s\n' "$identity" diff --git a/macOS/VirtualFileSystem/FileProviderExtension/Entitlements.plist b/macOS/VirtualFileSystem/FileProviderExtension/Entitlements.plist index 5ef5a63..3452ed5 100644 --- a/macOS/VirtualFileSystem/FileProviderExtension/Entitlements.plist +++ b/macOS/VirtualFileSystem/FileProviderExtension/Entitlements.plist @@ -6,7 +6,7 @@ com.apple.security.application-groups - 65S3A9JQ36.group.com.filesystem.vfs + YOURTEAMID.group.com.filesystem.vfs com.apple.security.files.downloads.read-write diff --git a/macOS/VirtualFileSystem/FileProviderExtension/FileProviderExtension.csproj b/macOS/VirtualFileSystem/FileProviderExtension/FileProviderExtension.csproj index 93b3615..5d8d359 100644 --- a/macOS/VirtualFileSystem/FileProviderExtension/FileProviderExtension.csproj +++ b/macOS/VirtualFileSystem/FileProviderExtension/FileProviderExtension.csproj @@ -1,11 +1,11 @@ - net8.0-macos + net10.0-macos Library enable true true - 10.15 + 12.0 True false false @@ -24,7 +24,8 @@ false true true - + + None None @@ -32,7 +33,8 @@ pdbonly true bin\Release - + + prompt 4 False @@ -42,7 +44,8 @@ true Entitlements.plist None - + + None 12.0 true @@ -54,19 +57,20 @@ - + - - + + - - + + - + +
\ No newline at end of file diff --git a/macOS/VirtualFileSystem/FileProviderExtension/Info.plist b/macOS/VirtualFileSystem/FileProviderExtension/Info.plist index 5d893ce..62ae0a4 100644 --- a/macOS/VirtualFileSystem/FileProviderExtension/Info.plist +++ b/macOS/VirtualFileSystem/FileProviderExtension/Info.plist @@ -6,6 +6,8 @@ en CFBundleDisplayName FileProviderExtension + SampleAppGroupId + YOURTEAMID.group.com.filesystem.vfs CFBundleIdentifier com.filesystem.vfs.app.extension CFBundleInfoDictionaryVersion @@ -21,7 +23,7 @@ CFBundleVersion 1 LSMinimumSystemVersion - 10.15 + 12.0 LSUIElement NSExtension @@ -46,7 +48,7 @@ NSExtensionFileProviderDocumentGroup - 65S3A9JQ36.group.com.filesystem.vfs + YOURTEAMID.group.com.filesystem.vfs NSPrincipalClass NSApplication diff --git a/macOS/VirtualFileSystem/FileProviderExtension/sign.sh b/macOS/VirtualFileSystem/FileProviderExtension/sign.sh index 0d2289f..b66009d 100644 --- a/macOS/VirtualFileSystem/FileProviderExtension/sign.sh +++ b/macOS/VirtualFileSystem/FileProviderExtension/sign.sh @@ -1 +1 @@ -find $1/FileProviderExtension.appex -iname '*.dylib' | while read libfile ; do codesign --force --sign - -o runtime --timestamp "${libfile}" ; done ; \ No newline at end of file +find $1/FileProviderExtension.appex -iname '*.dylib' | while read libfile ; do codesign --force --sign "${2:-Apple Development}" -o runtime --timestamp "${libfile}" ; done ; \ No newline at end of file diff --git a/macOS/VirtualFileSystem/README.md b/macOS/VirtualFileSystem/README.md index af2f67f..a77918a 100644 --- a/macOS/VirtualFileSystem/README.md +++ b/macOS/VirtualFileSystem/README.md @@ -5,10 +5,51 @@

You can download this sample and a trial license in the product download area. You can also clone it and browse the code on GitHub. 

Requirements

+

Build Setup for .NET 10

+

1. Select Xcode and install the workload

+

Install the .NET 10 SDK and a compatible Xcode. Open Xcode once to complete setup, then run:

+
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
+sudo xcodebuild -runFirstLaunch
+xcodebuild -version
+dotnet --version
+

For Xcode 26.0.1, select the compatible workload set from the sample directory:

+
sudo dotnet workload install macos --version 10.0.100
+dotnet workload --version
+dotnet workload list
+

Do not run an unversioned workload update while keeping this Xcode version: newer workloads may require newer Xcode. For other versions, select the matching workload set using the .NET for macOS release notes. Do not disable Xcode version validation.

+

2. Automatic Debug Team ID and signing

+

No manual Team ID replacement is needed for Debug builds. The build selects an installed development identity and obtains its actual TeamIdentifier by signing a temporary local executable, which is removed afterward. The certificate display name is not used to guess the Team ID.

+

For the app and extension, generated debug-signing/Info.plist and debug-signing/Entitlements.plist files under each project's intermediate output directory replace the template's YOURTEAMID with the detected team. The generated SampleAppGroupId, entitlement, and extension document group all use TEAMID.group.com.filesystem.vfs. SDK and post-build signing use these generated files; tracked templates remain unchanged. Storage reads the group ID from the current bundle's SampleAppGroupId entry.

+

Local macOS development using this Team-ID-prefixed group does not require provisioning profiles solely for app-group access or registration of the sample's bundle IDs in the developer portal. An installed valid development certificate and private key are still required. Distribution and iOS device deployment have separate requirements.

+

For Release builds, configure your own group in both projects' entitlements and Info.plist templates, including SampleAppGroupId and the extension's NSExtensionFileProviderDocumentGroup. Release does not generate these values automatically. Configure distribution identities and profiles as required; if changing bundle IDs, update their references consistently. Never commit private keys or profiles.

+
security find-identity -v -p codesigning
+

Debug builds automatically select the first valid Apple development identity reported by Keychain and use its exact fingerprint for SDK signing, embedded libraries, the app, and extension. Supported names are Apple Development, Mac Developer, and iPhone Developer. The repository contains no personal certificate name. With no installed valid development identity, the build stops with an actionable error rather than falling back to ad-hoc signing.

+

If several identities are installed, select one with -p:DebugSigningIdentity=YOUR_CERTIFICATE_SHA1 on dotnet build, using the fingerprint reported above. The override also applies to the custom signing scripts. The Team ID and matching app-group configuration are generated automatically for this identity. Keep the extension sandboxed.

+

3. Configure storage and build

+

Set the license and RemoteStorageRootPath in VirtualFileSystemMacApp/Resources/appsettings.json as described below. Use storage that the sandboxed extension is permitted to access, and do not publish personal license values.

+

Run from Sources/Samples/macOS/VirtualFileSystem. For Intel:

+
dotnet build VirtualFileSystemMacApp/VirtualFileSystemMacApp.csproj -c Debug -r osx-x64
+open "VirtualFileSystemMacApp/bin/Debug/net10.0-macos/osx-x64/Virtual Filesystem Sample.app"
+

For Apple Silicon, replace both occurrences of osx-x64 with osx-arm64. Building the container project builds and embeds the extension and signs the bundles. Launch the container app, not the extension, and use the menu-bar Install Extension command to mount the drive.

+

4. Verify and troubleshoot

+
codesign --verify --deep --strict --verbose=2 "VirtualFileSystemMacApp/bin/Debug/net10.0-macos/osx-x64/Virtual Filesystem Sample.app"
+codesign -dvv "VirtualFileSystemMacApp/bin/Debug/net10.0-macos/osx-x64/Virtual Filesystem Sample.app/Contents/PlugIns/FileProviderExtension.appex"
+codesign -d --entitlements - "VirtualFileSystemMacApp/bin/Debug/net10.0-macos/osx-x64/Virtual Filesystem Sample.app/Contents/PlugIns/FileProviderExtension.appex"
+ +

Release builds

+

The commands above build a development app, not a production installer. Release settings and sign_release.sh scripts must be configured for your own distribution identity, installer identity where applicable, and matching profiles. The existing Mac Developer selectors are legacy placeholders, not a universal distribution configuration. Developer ID distribution outside the App Store requires the appropriate signing and notarization workflow. Never commit profiles or private keys.

Solution Structure

The macOS sample solution consists of 3 projects: container application, an extension project, and a common code.

The container application provides a Menu Bar icon to install/uninstall the file system extension. Inside the container application, you should change the hardcoded directory to replicate in your Virtual Disk manually. Consider that the extension can only access sandbox folders (including Downloads, Pictures, Music, Movies). It means that it won't be able to show the contents of the folder outside of the sandbox.

@@ -17,7 +58,7 @@

Download the license file here. With the trial license, the product is fully functional and does not have any limitations. As soon as the trial license expires the product will stop working. Open the VirtualFilesystemMacApp/Resources/appsettings.json file and set the UserFileSystemLicense field. Set the license content directly as a value (NOT as a path to the license file). Do not forget to escape quotes: \":

  1. -
    "UserFileSystemLicense": "<?xml version=\"1.0\" encoding=\"utf-8\"?><License…
    +
    "UserFileSystemLicense": "<?xml version=\"1.0\" encoding=\"utf-8\"?><License�

You can also run the sample without explicitly specifying a license for 5 days. In this case, the Engine will automatically request the trial licenses from the IT Hit website https://www.userfilesystem.com. Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download trial licenses and specify them in appsettings.json

@@ -26,8 +67,7 @@
"RemoteStorageRootPath": "/Users/User1/Pictures/RemoteStorage"

Now you are ready to compile and run the project.

Running the Sample

-

Note that this sample does NOT require Group ID, App Identifies and Provisioning Profiles configuration for development. It is only required for production deployment.

-

To run the sample open the project in Visual Studio and run the project. The application adds an application to the macOS Status Bar. To mount the file system select the 'Install Extension' command in the Status Bar.

+

Install the toolchain and development certificate described above, then build and open the container app with the documented dotnet and open commands. The application adds an icon to the macOS Status Bar. To mount the file system select the 'Install Extension' command in the Status Bar.

Virtual File System Mac in .NET/C#

Note, that every File Provider Extension runs in a sandbox, so access to the local filesystem restricted by OS except Downloads, Pictures, Music, Movies public directories.

See also:

diff --git a/macOS/VirtualFileSystem/VirtualFileSystemCommon/SecureStorage.cs b/macOS/VirtualFileSystem/VirtualFileSystemCommon/SecureStorage.cs index 135114d..f1b54a0 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemCommon/SecureStorage.cs +++ b/macOS/VirtualFileSystem/VirtualFileSystemCommon/SecureStorage.cs @@ -8,7 +8,10 @@ public class SecureStorage : SecureStorageBase public const string BaseExtensionIdentifier = "com.userfilesystem.vfs.app"; public const string BaseExtensionDisplayName = "IT Hit File System"; - public SecureStorage() : base("65S3A9JQ36.group.com.filesystem.vfs") + private static string AppGroupId => Foundation.NSBundle.MainBundle.ObjectForInfoDictionary("SampleAppGroupId")?.ToString() + ?? throw new InvalidOperationException("SampleAppGroupId is missing from the app bundle's Info.plist."); + + public SecureStorage() : base(AppGroupId) { } diff --git a/macOS/VirtualFileSystem/VirtualFileSystemCommon/VirtualFilesystemCommon.csproj b/macOS/VirtualFileSystem/VirtualFileSystemCommon/VirtualFilesystemCommon.csproj index 316ccde..e27df4c 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemCommon/VirtualFilesystemCommon.csproj +++ b/macOS/VirtualFileSystem/VirtualFileSystemCommon/VirtualFilesystemCommon.csproj @@ -1,10 +1,10 @@ - net8.0-macos + net10.0-macos Library enable true - 10.15 + 12.0 false false diff --git a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/AppDelegate.cs b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/AppDelegate.cs index 1725eff..435e705 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/AppDelegate.cs +++ b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/AppDelegate.cs @@ -15,7 +15,6 @@ public class AppDelegate : NSApplicationDelegate private NSMenuItem InstallMenuItem = new NSMenuItem("Install FS Extension"); private NSMenuItem UninstallMenuItem = new NSMenuItem("Uninstall FS Extension"); private NSStatusItem StatusItem; - private SecureStorage secureStorage = new SecureStorage(); public AppDelegate() { diff --git a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Entitlements.plist b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Entitlements.plist index 11565db..252f59a 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Entitlements.plist +++ b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Entitlements.plist @@ -4,7 +4,7 @@ com.apple.security.application-groups - 65S3A9JQ36.group.com.filesystem.vfs + YOURTEAMID.group.com.filesystem.vfs com.apple.security.app-sandbox diff --git a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Info.plist b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Info.plist index 66e186e..6868e14 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Info.plist +++ b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/Info.plist @@ -4,6 +4,8 @@ CFBundleName VirtualFilesystemMacApp + SampleAppGroupId + YOURTEAMID.group.com.filesystem.vfs CFBundleIdentifier com.filesystem.vfs.app CFBundleShortVersionString @@ -11,7 +13,7 @@ CFBundleVersion 1 LSMinimumSystemVersion - 10.16 + 12.0 CFBundleDevelopmentRegion en CFBundleInfoDictionaryVersion diff --git a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/VirtualFileSystemMacApp.csproj b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/VirtualFileSystemMacApp.csproj index 2e5158a..5f727f9 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/VirtualFileSystemMacApp.csproj +++ b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/VirtualFileSystemMacApp.csproj @@ -1,11 +1,11 @@ - net8.0-macos + net10.0-macos Exe enable true true - 10.16 + 12.0 VirtualFilesystemMacApp Virtual Filesystem Sample @@ -13,13 +13,14 @@ false false None - adhoc + Apple Development pdbonly true bin\Release - + + prompt 4 false @@ -30,7 +31,8 @@ true Entitlements.plist None - + + None true Mac Developer @@ -43,6 +45,7 @@ + Assets.xcassets\AppIcon.appiconset\AppIcon-512%402x.png @@ -97,15 +100,15 @@ - + - + - + @@ -113,4 +116,5 @@ - + + \ No newline at end of file diff --git a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/sign.sh b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/sign.sh index c333dc4..cc5c6c8 100644 --- a/macOS/VirtualFileSystem/VirtualFileSystemMacApp/sign.sh +++ b/macOS/VirtualFileSystem/VirtualFileSystemMacApp/sign.sh @@ -1 +1 @@ -find "$1/Virtual Filesystem Sample.app" -iname '*.dylib' | while read libfile ; do codesign --force --sign - -o runtime --timestamp "${libfile}" ; done ; \ No newline at end of file +find "$1/Virtual Filesystem Sample.app" -iname '*.dylib' | while read libfile ; do codesign --force --sign "${2:-Apple Development}" -o runtime --timestamp "${libfile}" ; done ; \ No newline at end of file diff --git a/macOS/WebDAVDrive/README.md b/macOS/WebDAVDrive/README.md index e4cd792..3d5d88f 100644 --- a/macOS/WebDAVDrive/README.md +++ b/macOS/WebDAVDrive/README.md @@ -7,9 +7,49 @@

This sample is provided with IT Hit User File System v6.2 and later versions.

+

Build Setup for .NET 10

+

1. Select Xcode and install the workload

+

Install the .NET 10 SDK and a compatible Xcode first. Open Xcode once to finish setup, then select it for command-line builds:

+
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
+sudo xcodebuild -runFirstLaunch
+xcodebuild -version
+dotnet --version
+

For Xcode 26.0.1, run the following from the sample directory. This selects workload set 10.0.100 rather than the newest Apple SDK, which may require a newer Xcode:

+
sudo dotnet workload install macos --version 10.0.100
+dotnet workload --version
+dotnet workload list
+

Do not run an unversioned workload update when keeping this Xcode version. For a different Xcode release, choose the matching workload set using the .NET for macOS release notes. Do not disable Xcode version validation.

+

2. Automatic Debug Team ID and app group

+

No manual Team ID replacement is needed for Debug builds. The build selects an installed development identity and signs a temporary local executable to obtain its actual TeamIdentifier. It does not infer the Team ID from the certificate's display name. The temporary executable is removed afterward.

+

For each app and extension project, the build generates debug-signing/Info.plist and debug-signing/Entitlements.plist under the project's intermediate output directory. It replaces YOURTEAMID in those generated copies with the detected team, sets SampleAppGroupId, and uses the copies for SDK and post-build signing. Tracked templates remain unchanged. The common storage code reads SampleAppGroupId from the running bundle rather than hardcoding a Team ID.

+

The app and both extensions therefore use the same TEAMID.group.com.test.webdavdrive group. Local macOS development with this Team-ID-prefixed group does not require creating provisioning profiles solely for the app-group entitlement or registering the sample's bundle IDs in the developer portal. A valid installed development certificate with its private key is still required. This does not apply to iOS device deployment or distribution-specific requirements. The iOS group ID and authentication configuration are unchanged.

+

Release builds do not perform this automatic configuration. Before distributing, configure your own group consistently in all three projects' entitlements and Info.plist templates (including SampleAppGroupId and the extensions' NSExtensionFileProviderDocumentGroup), signing identities, and any required profiles. If changing bundle IDs, update their references in code and project settings too. Do not commit profiles or private keys.

+

3. Check signing and configure the server

+
security find-identity -v -p codesigning
+

Debug builds automatically select the first valid Apple development identity reported by Keychain and use its exact certificate fingerprint for SDK signing, embedded libraries, the app, and both extensions. Supported names are Apple Development, Mac Developer, and iPhone Developer. No personal certificate name is stored in the sample. If no valid identity is installed, the build stops with an actionable error; it does not silently fall back to ad-hoc signing.

+

To select a different installed identity, pass -p:DebugSigningIdentity=YOUR_CERTIFICATE_SHA1 to dotnet build, using the fingerprint reported by the command above. This single override also applies to the custom post-build signing steps. The Team ID and matching app-group configuration are generated automatically for this identity. Keep extensions sandboxed.

+

Configure the licenses, WebDAV URL, and optional WebSocket URL in WebDAVMacApp/Resources/appsettings.json as described below. Do not publish credentials or personal license values.

+

4. Build and run

+

Run these commands from Sources/Samples/macOS/WebDAVDrive. Use osx-x64 on Intel or osx-arm64 on Apple Silicon:

+
dotnet build WebDAVMacApp/WebDAVMacApp.csproj -c Debug -r osx-x64
+open "WebDAVMacApp/bin/Debug/net10.0-macos/osx-x64/WebDAV Drive.app"
+

Replace both occurrences of osx-x64 when building for Apple Silicon. Building the container project also builds and embeds both extensions and signs the bundles. Do not launch an extension independently. Use the app's menu-bar commands to install/mount the drive.

+

5. Verify and troubleshoot

+
codesign --verify --deep --strict --verbose=2 "WebDAVMacApp/bin/Debug/net10.0-macos/osx-x64/WebDAV Drive.app"
+codesign -dvv "WebDAVMacApp/bin/Debug/net10.0-macos/osx-x64/WebDAV Drive.app/Contents/PlugIns/WebDAVFileProviderExtension.appex"
+codesign -d --entitlements - "WebDAVMacApp/bin/Debug/net10.0-macos/osx-x64/WebDAV Drive.app/Contents/PlugIns/WebDAVFileProviderExtension.appex"
+

Server Requirements

This sample requires WebDAV server with collections synchronization support. The following samples support collections synchronization:

@@ -29,7 +69,7 @@

Setting License

Note that to use the sample you need both the IT Hit WebDAV Client Library license and IT Hit User File System license.

To run the example, you will need both IT Hit WebDAV Client Library for .NET license and IT Hit User File System Engine for .NET License. You can download a WebDAV Client for .NET trial license in the IT Hit WebDAV Client Library product download area and the User File System trial license in the IT Hit User File System product download area. Note that this sample is fully functional with a trial licenses and does not have any limitations. The trial licenses are valid for one month will stop working after this. You can check the expiration date inside the license file. Download the license files and specify license strings in the WebDAVClientLicense and UserFileSystemLicense fields respectively in WebDAVMacApp\Resources\appsettings.json file. Set the license content directly as a value (NOT as a path to the license file). Do not forget to escape quotes: \":

-
"UserFileSystemLicense": "<?xml version=\"1.0\" encoding=\"utf-8\"?><License…
+
"UserFileSystemLicense": "<?xml version=\"1.0\" encoding=\"utf-8\"?><License�

You can also run the sample without explicitly specifying a license for 5 days. In this case, the Engine will automatically request the trial licenses from the IT Hit website https://www.userfilesystem.com. Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download trial licenses and specify them in appsettings.json

Setting WebDAV Server URL

To specify the WebDAV server URL edit the "WebDAVServerUrl" parameter in appsettings.json. This could be either a server root path (https://server/) or a WebDAV folder on your server (https://server/dav/).

@@ -40,22 +80,18 @@

In case you are using IT Hit demo servers, you will specify the demo server root, without user folder: wss://webdavserver.net or wss://webdavserver.com. 

"WebSocketServerUrl": "wss://webdavserver.net"
-

Note that this sample does NOT require Group ID, App Identifies and Provisioning Profiles configuration for development. It is required only required for production deployment.

+

Install the toolchain and development certificate described above before running. Debug builds automatically resolve the Team ID and app group; source templates do not need manual editing.

To run the sample:

    -
  1. Open the project in Visual Studio and run the project. The application is added to the macOS Status Bar.
  2. +
  3. Build the container project with dotnet and open the resulting app bundle as shown above. The application is added to the macOS Status Bar.
  4. Select 'Install Extension' command in the Status Bar. This will mount your WebDAV file system.

Now you can manage documents using Finder, command prompt or by any other means. You can find the new file system in the 'Locations' sections in Finder. 

For the development and testing convenience, when installing the extension, it will automatically open an instance of Finder with a mounted file system as well as will launch a default web browser navigating to the WebDAV server URL specified in your appsettings.json:

WebDAV Drive for macOS sample

-

To create installer for testing purposes and install the sample to /Application folder follow this steps:

-
    -
  1. You need Mac Developer certificate to sign app and 3rd Party Mac Developer Installer certificate to sign pkg. To get them use this guide.
  2. -
  3. Start Release build.
  4. -
  5. Then open Release output folder and find WebDAV Drive signed.pkg and use this pkg to install the Sample on the same host.
  6. -
+

The Debug commands above build a development app, not a distributable installer. Release signing and packaging targets are templates that must be configured for your distribution method. Review the Release project settings, signing targets, and sign_release.sh scripts; select your distribution/installer identities and provide the matching provisioning profiles where required. The WebDAV Release targets expect a local embedded.provisionprofile in the app and each extension project directory. Never commit those profiles or signing private keys.

+

After configuring all Release targets, build with dotnet build WebDAVMacApp/WebDAVMacApp.csproj -c Release -r osx-x64. Developer ID distribution outside the App Store also requires the appropriate signing/notarization workflow; a successful Debug build is not a production-deployment validation.

For production environment you need to create Group ID, App Identifies and Provisioning Profiles configuration as described in this article.

See also: