From 3c5c222ad467598a6fe870865624e9369f83662a Mon Sep 17 00:00:00 2001 From: MysticILD <173185810+MysticILD@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:01:10 +0200 Subject: [PATCH 1/4] feat: add iOS support --- .github/workflows/build-ios.yml | 24 ++- CONTRIBUTING.md | 34 +++- OpenUtau.Core/Util/Onnx.cs | 6 +- OpenUtauMobile.iOS/AppDelegate.cs | 119 ++++++++++++- OpenUtauMobile.iOS/Info.plist | 41 ++++- OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj | 6 +- .../Services/Audio/IosAudioOutput.cs | 162 ++++++++++++++++-- OpenUtauMobile/Assets/Lang/Strings.en.resx | 3 + OpenUtauMobile/Assets/Lang/Strings.ja.resx | 3 + OpenUtauMobile/Assets/Lang/Strings.ru.resx | 3 + OpenUtauMobile/Assets/Lang/Strings.uk.resx | 3 + .../Assets/Lang/Strings.zh-Hans.resx | 3 + .../NoteExtraction/GameBackendProvider.cs | 6 +- OpenUtauMobile/ViewLocator.cs | 35 +++- .../NoteExtractionPopupViewModel.cs | 12 +- README.md | 24 ++- docs/CONTRIBUTING.en-US.md | 33 ++++ docs/PLATFORMS.md | 14 +- native/worldline/README.md | 2 +- 19 files changed, 481 insertions(+), 52 deletions(-) diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index 1f8e196f..2e216ae3 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -132,7 +132,6 @@ jobs: -p:PublishAot=false \ -p:UseMonoRuntime=true \ -p:MtouchUseLlvm=false \ - -p:UseInterpreter=false \ -p:TrimMode=partial \ -p:MtouchLink=SdkOnly \ -p:EnableAssemblyILStripping=false \ @@ -171,6 +170,29 @@ jobs: BUILD_VERSION="$(plutil -extract CFBundleVersion raw "$INFO_PLIST")" PLATFORM="$(plutil -extract CFBundleSupportedPlatforms.0 raw "$INFO_PLIST")" ARCHS="$(lipo -archs "$APP_DIR/$EXECUTABLE")" + python - "$INFO_PLIST" <<'PY' + import plistlib + import sys + + with open(sys.argv[1], "rb") as stream: + info = plistlib.load(stream) + + minimum = tuple(int(part) for part in info.get("MinimumOSVersion", "0").split(".")) + if minimum[:2] < (15, 1): + raise SystemExit(f"MinimumOSVersion is {info.get('MinimumOSVersion')}, expected at least 15.1") + + project_uti = "pers.vocoder712.openutaumobile.ustx" + document_types = info.get("CFBundleDocumentTypes", []) + if not any(project_uti in item.get("LSItemContentTypes", []) for item in document_types): + raise SystemExit(f"IPA does not register the USTX document type {project_uti}") + + if "audio" not in info.get("UIBackgroundModes", []): + raise SystemExit("IPA does not declare the audio background mode") + + print(f"Minimum OS: {info['MinimumOSVersion']}") + print("USTX document type: registered") + print("Background audio: enabled") + PY python native/worldline/verify_static.py \ artifacts/worldline-native/ios-arm64/libworldline.a ios-arm64 \ --nm "$(xcrun --find nm)" --app-bundle "$APP_DIR" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f7c4261..1b69529d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -196,7 +196,39 @@ dotnet build OpenUtauMobile.Android/OpenUtauMobile.Android.csproj -c Debug -r $a 菜单名称可能随 Rider 版本变化,参见 [Rider Android 调试说明](https://www.jetbrains.com/help/rider/Run_Debug_Configuration_Xamarin_Android.html)。 Debug 使用独立应用 ID 和本地调试签名,无需配置 CI 的发布签名密钥。 -### 6. 常见问题 +### 6. 构建 iOS(macOS) + +iOS 项目必须在 macOS 和 Xcode 上构建;Windows 本地构建不能替代 iOS SDK、模拟器或设备验证。 +当前 CI 固定使用 Xcode 27.0、.NET SDK 10.0.401 和 workload set 10.0.401.1。先在仓库根目录检查 +`xcodebuild -version` 与 `dotnet --version`,然后安装项目所需 workload: + +```bash +export AVALONIA_TELEMETRY_OPTOUT=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +dotnet workload restore OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj --version 10.0.401.1 +``` + +构建 ARM64 和 x64 模拟器宿主: + +```bash +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-arm64 -p:EnableCodeSigning=false +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-x64 -p:EnableCodeSigning=false +``` + +构建 ARM64 设备用的未签名 IPA: + +```bash +dotnet publish OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r ios-arm64 \ + -p:EnableCodeSigning=false -p:BuildIpa=true -p:PublishAot=false -p:UseMonoRuntime=true \ + -p:MtouchUseLlvm=false -p:TrimMode=partial -p:MtouchLink=SdkOnly \ + -p:EnableAssemblyILStripping=false -p:_IsDedupEnabled=false +``` + +未签名 IPA 可检查打包内容,但必须使用 Apple 开发证书和 provisioning profile 签名后才能安装到设备。 +在模拟器或设备上检查文档导入、音频路由变化和系统中断后的播放恢复、WORLDLINE 合成及 ONNX 推理; +构建成功只验证了编译和打包,不等同于运行时支持。 + +### 7. 常见问题 | 现象 | 检查与处理 | | --- | --- | diff --git a/OpenUtau.Core/Util/Onnx.cs b/OpenUtau.Core/Util/Onnx.cs index f19d0720..a7777fa1 100644 --- a/OpenUtau.Core/Util/Onnx.cs +++ b/OpenUtau.Core/Util/Onnx.cs @@ -46,7 +46,7 @@ public static List getRunnerOptions() { runners.Add("DirectML"); } return runners; - } else if (OS.IsMacOS()) { + } else if (OS.IsMacOS() || OS.IsIOS()) { return new List { "CPU", "CoreML" @@ -232,7 +232,7 @@ public static InferenceSession getInferenceSession(byte[] model, OnnxRunnerChoic return new InferenceSession(model); } else { // Try with CoreML subgraphs enabled first, fallback to default if it fails - if (OS.IsMacOS() && Preferences.Default.OnnxRunner == "CoreML") { + if ((OS.IsMacOS() || OS.IsIOS()) && Preferences.Default.OnnxRunner == "CoreML") { try { using var subgraphOptions = getOnnxSessionOptions(coremlEnableOnSubgraphs: true); return new InferenceSession(model, subgraphOptions); @@ -259,7 +259,7 @@ public static InferenceSession getInferenceSession(string modelPath, OnnxRunnerC return new InferenceSession(modelPath); } else { // Try with CoreML subgraphs enabled first, fallback to default if it fails - if (OS.IsMacOS() && Preferences.Default.OnnxRunner == "CoreML") { + if ((OS.IsMacOS() || OS.IsIOS()) && Preferences.Default.OnnxRunner == "CoreML") { try { using var subgraphOptions = getOnnxSessionOptions(coremlEnableOnSubgraphs: true); return new InferenceSession(modelPath, subgraphOptions); diff --git a/OpenUtauMobile.iOS/AppDelegate.cs b/OpenUtauMobile.iOS/AppDelegate.cs index 8faa4694..f261c07a 100644 --- a/OpenUtauMobile.iOS/AppDelegate.cs +++ b/OpenUtauMobile.iOS/AppDelegate.cs @@ -1,11 +1,13 @@ using System; using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; using Foundation; using Avalonia; using Avalonia.Media; using Avalonia.iOS; +using ObjCRuntime; using ReactiveUI.Avalonia; using Microsoft.ML.OnnxRuntime; using OpenUtau.Audio; @@ -50,10 +52,125 @@ protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) }); } + /// + /// 接收文件提供程序交给应用打开的 USTX 工程。 + /// + [Export("application:openURL:options:")] + public new bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) + { + if (!IsSupportedProjectUrl(url)) + { + return base.OpenUrl(app, url, options); + } + + _ = OpenProjectDocumentAsync(url); + return true; + } + + /// + /// 判断系统交给应用的文件是否为 USTX 工程。 + /// + private static bool IsSupportedProjectUrl(NSUrl url) + { + return url.IsFileUrl && + !string.IsNullOrEmpty(url.Path) && + string.Equals(Path.GetExtension(url.Path), ".ustx", StringComparison.OrdinalIgnoreCase); + } + + /// + /// 在安全作用域仍有效时复制外部工程,并交给共享导航队列打开。 + /// + private static async Task OpenProjectDocumentAsync(NSUrl url) + { + bool hasSecurityScope = false; + try + { + hasSecurityScope = url.StartAccessingSecurityScopedResource(); + string localPath = await Task.Run(() => CopyProjectDocumentToCache(url)); + ExternalProjectOpenService.Enqueue(new ExternalProjectOpenRequest(localPath, DeleteSourceAfterRead: true)); + } + catch (Exception exception) + { + Log.Error(exception, "无法从 iOS 文件提供程序导入 USTX 工程"); + ExternalProjectOpenService.ReportFailure(exception); + } + finally + { + if (hasSecurityScope) + { + url.StopAccessingSecurityScopedResource(); + } + } + } + + /// + /// 协调读取系统文件提供程序中的工程,并复制到应用缓存。 + /// + private static string CopyProjectDocumentToCache(NSUrl sourceUrl) + { + if (string.IsNullOrEmpty(sourceUrl.Path)) + { + throw new IOException(L.S("Ios.Document.ImportFailed")); + } + string importDirectory = Path.Combine(PathManager.Inst.CachePath, "DocumentImports"); + Directory.CreateDirectory(importDirectory); + string destinationPath = Path.Combine(importDirectory, $"{Guid.NewGuid():N}.ustx"); + + using NSFileCoordinator coordinator = new(null); + Exception? copyException = null; + coordinator.CoordinateRead( + sourceUrl, + NSFileCoordinatorReadingOptions.WithoutChanges, + out NSError? coordinationError, + coordinatedUrl => + { + try + { + string coordinatedPath = coordinatedUrl.Path + ?? throw new IOException(L.S("Ios.Document.ImportFailed")); + File.Copy(coordinatedPath, destinationPath); + } + catch (Exception exception) + { + copyException = exception; + try + { + if (File.Exists(destinationPath)) + { + File.Delete(destinationPath); + } + } + catch (Exception cleanupException) when (cleanupException is IOException or UnauthorizedAccessException) + { + // 保留原始复制异常,缓存目录由应用独占。 + } + } + }); + + if (coordinationError != null) + { + throw new IOException(coordinationError.LocalizedDescription); + } + if (copyException != null) + { + throw new IOException(L.S("Ios.Document.ImportFailed"), copyException); + } + + if (!File.Exists(destinationPath)) + { + throw new IOException(L.S("Ios.Document.ImportFailed")); + } + + return destinationPath; + } + private static void InitPathManager() { string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); - string cachePath = Path.Combine(dataPath, "Cache"); + string cachePath = NSFileManager.DefaultManager + .GetUrls(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User) + .FirstOrDefault()?.Path + ?? throw new InvalidOperationException("无法获取 iOS 缓存目录。"); PathManagerInitialization.Initialize( rootPath: dataPath, dataPath: dataPath, diff --git a/OpenUtauMobile.iOS/Info.plist b/OpenUtauMobile.iOS/Info.plist index a62bde20..ba6984f9 100644 --- a/OpenUtauMobile.iOS/Info.plist +++ b/OpenUtauMobile.iOS/Info.plist @@ -4,6 +4,43 @@ CFBundleDisplayName OpenUtau Mobile 预览版 + UTExportedTypeDeclarations + + + UTTypeIdentifier + pers.vocoder712.openutaumobile.ustx + UTTypeDescription + OpenUtau Project + UTTypeConformsTo + + public.data + + UTTypeTagSpecification + + public.filename-extension + + ustx + + public.mime-type + application/x-openutau-project + + + + CFBundleDocumentTypes + + + CFBundleTypeName + OpenUtau Project + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSItemContentTypes + + pers.vocoder712.openutaumobile.ustx + + + LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace @@ -17,9 +54,9 @@ LaunchScreen UIFileSharingEnabled - UIRequiredDeviceCapabilities + UIBackgroundModes - armv7 + audio UISupportedInterfaceOrientations diff --git a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj index 9c9e46ee..3b6e0b72 100644 --- a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj +++ b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj @@ -2,16 +2,16 @@ Exe net10.0-ios - 15.0 + 15.1 enable - + false false - false + OpenUtau.Plugin.Builtin,OpenUtau.Core partial false diff --git a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs index 773ccfc3..31402de4 100644 --- a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs +++ b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs @@ -22,17 +22,21 @@ internal sealed class IosAudioOutput : IAudioOutput, IDisposable private readonly AVAudioEngine engine; private readonly AVAudioSourceNode sourceNode; private readonly AVAudioFormat outputFormat; + private readonly NSObject interruptionObserver; + private readonly NSObject routeChangeObserver; private ISampleProvider? sampleProvider; private PlaybackState playbackState = PlaybackState.Stopped; private float[] interleavedBuffer = Array.Empty(); private float[] leftBuffer = Array.Empty(); private float[] rightBuffer = Array.Empty(); private long playedFrames; + private bool interruptionActive; + private bool resumeAfterInterruption; private bool disposed; public IosAudioOutput() { - ConfigureAudioSession(); + ActivateAudioSession(); outputFormat = new AVAudioFormat(SampleRate, ChannelCount); engine = new AVAudioEngine(); sourceNode = new AVAudioSourceNode( @@ -41,6 +45,10 @@ public IosAudioOutput() engine.AttachNode(sourceNode); engine.Connect(sourceNode, engine.MainMixerNode, outputFormat); engine.Prepare(); + interruptionObserver = AVAudioSession.Notifications.ObserveInterruption( + (_, args) => OnAudioInterruption(args.Notification)); + routeChangeObserver = AVAudioSession.Notifications.ObserveRouteChange( + (_, _) => TryRestartAfterRouteChange()); Log.Information("AVAudioEngine 音频后端初始化成功"); } @@ -94,6 +102,8 @@ public void Init(ISampleProvider provider) sampleProvider = preparedProvider; playedFrames = 0; playbackState = PlaybackState.Stopped; + interruptionActive = false; + resumeAfterInterruption = false; } } @@ -102,36 +112,47 @@ public void Play() ThrowIfDisposed(); lock (syncRoot) { - if (sampleProvider == null || playbackState == PlaybackState.Playing) + if (sampleProvider == null || playbackState == PlaybackState.Playing || interruptionActive) { return; } playbackState = PlaybackState.Playing; } - if (!engine.Running) + try { - bool started = engine.StartAndReturnError(out NSError? error); - if (!started) + StartEngine(); + } + catch + { + lock (syncRoot) { - lock (syncRoot) - { - playbackState = PlaybackState.Stopped; - } - throw new InvalidOperationException(error?.LocalizedDescription ?? "AVAudioEngine failed to start."); + playbackState = PlaybackState.Stopped; } + throw; } } public void Pause() { + bool pauseEngine = false; lock (syncRoot) { + if (interruptionActive) + { + resumeAfterInterruption = false; + return; + } if (playbackState == PlaybackState.Playing) { playbackState = PlaybackState.Paused; + pauseEngine = true; } } + if (pauseEngine) + { + engine.Pause(); + } } public void Stop() @@ -140,7 +161,9 @@ public void Stop() { playbackState = PlaybackState.Stopped; playedFrames = 0; + resumeAfterInterruption = false; } + engine.Pause(); } public void SelectDevice(Guid guid, int deviceNumber) @@ -155,6 +178,8 @@ public void Dispose() return; } disposed = true; + interruptionObserver.Dispose(); + routeChangeObserver.Dispose(); engine.Stop(); engine.DetachNode(sourceNode); sourceNode.Dispose(); @@ -226,7 +251,10 @@ private void CopyToNativeBuffers(AudioBuffers outputData, int frameCount) Marshal.Copy(rightBuffer, 0, right.Data, frameCount); } - private static void ConfigureAudioSession() + /// + /// 激活系统播放会话,允许用户在切换应用后继续收听当前回放。 + /// + private static void ActivateAudioSession() { AVAudioSession session = AVAudioSession.SharedInstance(); NSString category = AVAudioSessionCategory.Playback.GetConstant() @@ -243,6 +271,118 @@ private static void ConfigureAudioSession() } } + /// + /// 启动或恢复 AVAudioEngine,并在系统中断结束后重新激活音频会话。 + /// + private void StartEngine() + { + ActivateAudioSession(); + if (engine.Running) + { + return; + } + + bool started = engine.StartAndReturnError(out NSError? error); + if (!started) + { + throw new InvalidOperationException(error?.LocalizedDescription ?? "AVAudioEngine failed to start."); + } + } + + /// + /// 在通话等系统中断期间暂停播放,并仅在系统允许时恢复。 + /// + private void OnAudioInterruption(NSNotification notification) + { + long typeValue = GetNotificationNumber(notification, "AVAudioSessionInterruptionTypeKey"); + if ((AVAudioSessionInterruptionType)typeValue == AVAudioSessionInterruptionType.Began) + { + lock (syncRoot) + { + interruptionActive = true; + resumeAfterInterruption = playbackState == PlaybackState.Playing; + if (resumeAfterInterruption) + { + playbackState = PlaybackState.Paused; + } + } + engine.Pause(); + Log.Information("iOS 音频会话被中断,已暂停回放"); + return; + } + + if ((AVAudioSessionInterruptionType)typeValue != AVAudioSessionInterruptionType.Ended) + { + return; + } + + long optionsValue = GetNotificationNumber(notification, "AVAudioSessionInterruptionOptionKey"); + bool resume; + lock (syncRoot) + { + interruptionActive = false; + resume = resumeAfterInterruption && + (((AVAudioSessionInterruptionOptions)optionsValue & + AVAudioSessionInterruptionOptions.ShouldResume) != 0); + resumeAfterInterruption = false; + } + + if (resume) + { + try + { + Play(); + } + catch (Exception exception) + { + lock (syncRoot) + { + playbackState = PlaybackState.Paused; + } + Log.Warning(exception, "iOS 音频中断结束后无法恢复回放"); + } + } + } + + /// + /// 输出设备变化后恢复仍处于播放状态的音频引擎。 + /// + private void TryRestartAfterRouteChange() + { + lock (syncRoot) + { + if (interruptionActive || playbackState != PlaybackState.Playing) + { + return; + } + } + + try + { + StartEngine(); + } + catch (Exception exception) + { + lock (syncRoot) + { + if (playbackState == PlaybackState.Playing) + { + playbackState = PlaybackState.Paused; + } + } + Log.Warning(exception, "iOS 音频输出路由变化后无法恢复 AVAudioEngine"); + } + } + + /// + /// 从系统音频通知中读取数值字段。 + /// + private static long GetNotificationNumber(NSNotification notification, string key) + { + using NSString nativeKey = new(key); + return (notification.UserInfo?.ObjectForKey(nativeKey) as NSNumber)?.Int64Value ?? 0; + } + private void ThrowIfDisposed() { ObjectDisposedException.ThrowIf(disposed, this); diff --git a/OpenUtauMobile/Assets/Lang/Strings.en.resx b/OpenUtauMobile/Assets/Lang/Strings.en.resx index f19b641e..5b344c3a 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.en.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.en.resx @@ -514,6 +514,9 @@ Access to this folder is denied + + OpenUtau Mobile could not import the selected USTX project. + Go to parent folder diff --git a/OpenUtauMobile/Assets/Lang/Strings.ja.resx b/OpenUtauMobile/Assets/Lang/Strings.ja.resx index cae11ec4..eacbb848 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ja.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ja.resx @@ -514,6 +514,9 @@ このフォルダーへのアクセスが拒否されました + + 選択した USTX プロジェクトを読み込めませんでした。 + 上のフォルダーへ移動 diff --git a/OpenUtauMobile/Assets/Lang/Strings.ru.resx b/OpenUtauMobile/Assets/Lang/Strings.ru.resx index ff679fe1..1db8f405 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ru.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ru.resx @@ -443,6 +443,9 @@ Доступ к этой папке запрещён + + Не удалось импортировать выбранный проект USTX. + Перейти в родительскую папку diff --git a/OpenUtauMobile/Assets/Lang/Strings.uk.resx b/OpenUtauMobile/Assets/Lang/Strings.uk.resx index 5e01610c..2ec1c56a 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.uk.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.uk.resx @@ -443,6 +443,9 @@ Доступ до цієї теки заборонено + + Не вдалося імпортувати вибраний проєкт USTX. + Перейти до батьківської теки diff --git a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx index 9efa6176..a94a6eca 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx @@ -514,6 +514,9 @@ 无权访问此目录 + + 无法导入所选的 USTX 工程。 + 返回上级目录 diff --git a/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs b/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs index 89d21967..fff820af 100644 --- a/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs +++ b/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs @@ -18,7 +18,9 @@ internal sealed record GameDependency(string PackageId, string? Path, GameConfig internal static class GameBackendProvider { - public static bool IsSupported => !OperatingSystem.IsBrowser() && !OperatingSystem.IsIOS(); + /// 按平台与运行库检查 GAME 后端是否可用。 + public static bool IsSupported(NoteExtractionBackend choice) => + !OperatingSystem.IsBrowser() && (choice == NoteExtractionBackend.Onnx || !OperatingSystem.IsIOS()); // 弹窗只读取模型文件与配置,不在 UI 线程创建推理会话。 public static GameDependency Inspect(NoteExtractionBackend choice) @@ -55,7 +57,7 @@ public static GameDependency Inspect(NoteExtractionBackend choice) public static IGameBackend Create(NoteExtractionBackend choice) { - if (!IsSupported) throw new PlatformNotSupportedException(L.S("NoteExtraction.Unsupported")); + if (!IsSupported(choice)) throw new PlatformNotSupportedException(L.S("NoteExtraction.Unsupported")); GameDependency dependency = Inspect(choice); if (!dependency.IsInstalled) { diff --git a/OpenUtauMobile/ViewLocator.cs b/OpenUtauMobile/ViewLocator.cs index 3bb67b02..5cd2dc1e 100644 --- a/OpenUtauMobile/ViewLocator.cs +++ b/OpenUtauMobile/ViewLocator.cs @@ -1,13 +1,35 @@ using System; +using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Templates; using OpenUtauMobile.ViewModels; +using OpenUtauMobile.Views; using Serilog; namespace OpenUtauMobile; public class ViewLocator : IDataTemplate { + // 显式视图工厂让 AOT 编译器看到每个页面构造函数,避免 iOS 运行时反射 JIT。 + private static readonly IReadOnlyDictionary> ViewFactories = new Dictionary> + { + [typeof(AboutViewModel)] = static () => new AboutView(), + [typeof(ClassicSingerSetupViewModel)] = static () => new ClassicSingerSetupView(), + [typeof(DependencyManagerViewModel)] = static () => new DependencyManagerView(), + [typeof(EditorViewModel)] = static () => new EditorView(), + [typeof(ExportLogsViewModel)] = static () => new ExportLogsView(), + [typeof(ExpressionGraphEditorViewModel)] = static () => new ExpressionGraphEditorView(), + [typeof(ExpressionGraphLibraryViewModel)] = static () => new ExpressionGraphLibraryView(), + [typeof(HomeViewModel)] = static () => new HomeView(), + [typeof(OptionsViewModel)] = static () => new OptionsView(), + [typeof(PluginManagerViewModel)] = static () => new PluginManagerView(), + [typeof(SandboxFileManagerViewModel)] = static () => new SandboxFileManagerView(), + [typeof(SettingsViewModel)] = static () => new SettingsView(), + [typeof(SingerDetailViewModel)] = static () => new SingerDetailView(), + [typeof(SingerManagementViewModel)] = static () => new SingerManagementView(), + [typeof(SplashScreenViewModel)] = static () => new SplashScreenView(), + }; + public Control? Build(object? data) { if (data is null) @@ -15,25 +37,24 @@ public class ViewLocator : IDataTemplate return null; } - string name = data.GetType().FullName!.Replace("ViewModel", "View"); - Type? type = Type.GetType(name); - if (type != null) + Type viewModelType = data.GetType(); + if (ViewFactories.TryGetValue(viewModelType, out Func? createView)) { try { - return (Control)Activator.CreateInstance(type)!; + return createView(); } catch (Exception exception) { - Log.Error(exception, "创建视图 {ViewType} 失败", name); + Log.Error(exception, "创建视图 {ViewModelType} 失败", viewModelType.FullName); return new TextBlock { - Text = $"Failed to create view: {name}\n{exception.GetBaseException().Message}" + Text = $"Failed to create view: {viewModelType.FullName}\n{exception.GetBaseException().Message}" }; } } - return new TextBlock { Text = "Not Found: " + name }; + return new TextBlock { Text = "Not Found: " + viewModelType.FullName }; } public bool Match(object? data) diff --git a/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs b/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs index fd94c4a7..929db7f4 100644 --- a/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs +++ b/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs @@ -35,10 +35,10 @@ public sealed class NoteExtractionPopupViewModel : PopupViewModelBase && BatchSize is >= 1 and <= 32 && BatchSize == decimal.Truncate(BatchSize.Value) && MaxBatchDuration is >= 0 and <= 600 && (!ExtractPitch || RmvpeAvailable); public bool HasInvalidSettings => !Valid; - public bool CanUseOnnx => GameBackendProvider.IsSupported && Valid && onnx.IsInstalled && onnx.SupportsLanguage(Language?.Code); - public bool CanUseGgml => GameBackendProvider.IsSupported && Valid && ggml.IsInstalled && ggml.SupportsLanguage(Language?.Code); - public string OnnxStatus => Status("ONNX", onnx); - public string GgmlStatus => Status("GGML", ggml); + public bool CanUseOnnx => GameBackendProvider.IsSupported(NoteExtractionBackend.Onnx) && Valid && onnx.IsInstalled && onnx.SupportsLanguage(Language?.Code); + public bool CanUseGgml => GameBackendProvider.IsSupported(NoteExtractionBackend.Ggml) && Valid && ggml.IsInstalled && ggml.SupportsLanguage(Language?.Code); + public string OnnxStatus => Status("ONNX", onnx, NoteExtractionBackend.Onnx); + public string GgmlStatus => Status("GGML", ggml, NoteExtractionBackend.Ggml); public ReactiveCommand OnnxCommand { get; } public ReactiveCommand GgmlCommand { get; } public ReactiveCommand CancelCommand { get; } @@ -74,8 +74,8 @@ or nameof(BatchSize) or nameof(MaxBatchDuration)) }; } - private string Status(string name, GameDependency dependency) => string.Format(L.S("NoteExtraction.BackendStatus"), - name, dependency.PackageId, L.S(!GameBackendProvider.IsSupported ? "NoteExtraction.Unsupported" + private string Status(string name, GameDependency dependency, NoteExtractionBackend backend) => string.Format(L.S("NoteExtraction.BackendStatus"), + name, dependency.PackageId, L.S(!GameBackendProvider.IsSupported(backend) ? "NoteExtraction.Unsupported" : !dependency.IsInstalled ? "NoteExtraction.NotInstalled" : dependency.SupportsLanguage(Language?.Code) ? "Common.Installed" : "NoteExtraction.LanguageUnavailable")); diff --git a/README.md b/README.md index 6d00c9f6..2889bf29 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This is a developer preview. The tables describe the current source and packagin | Android | ARM64 (`arm64-v8a`), x64 (`x86_64`) | Minimum Android 7 / API 24; ARM64 and x64 local APK builds verified. | | Linux | x64, ARM64 | Desktop host and release jobs configured; use a matching Linux build host. | | macOS | x64, ARM64 | Desktop host and release jobs configured; build on macOS. | -| iOS | Simulator build configuration exists | Experimental host with AVAudioEngine audio and ONNX initialization; full feature parity is not established. Requires macOS/Xcode for development. | +| iOS | ARM64 device IPA; ARM64 and x64 simulator builds configured | .NET 10 host and unsigned IPA build are configured with iOS 15.1 minimum. Full runtime and device behavior still need validation. Requires macOS/Xcode for development. | | Browser / WebAssembly | Browser host exists | Experimental; Dummy audio output, no complete singing synthesis runtime integration. | Windows x86 and Android x86/ARM32 have some project/toolchain mappings but are not part of the current release matrix. @@ -50,20 +50,21 @@ is incomplete. **Unavailable** means the feature is not exposed or its required | Feature | Windows | Android | Linux | macOS | iOS | Browser | | --- | --- | --- | --- | --- | --- | --- | | Shared project / piano-roll editor | Integrated | Integrated | Integrated | Integrated | Experimental | Experimental | +| Built-in phonemizers | Integrated | Integrated | Integrated | Integrated | Experimental; Mono interpreter configured for reflection-created phonemizers, device validation pending | Experimental | | Desktop workspace, persistent inspectors and tool manager | Integrated; local checks below | Uses mobile presentation | Integrated; host verification pending | Integrated; host verification pending | Uses mobile presentation | Uses mobile presentation | | Audio playback | Integrated | Integrated | Integrated | Integrated | Experimental (AVAudioEngine) | Unavailable (Dummy output) | -| Built-in worldline / WORLDLINE-R synthesis | Integrated | Integrated; page-size limitation below | Integrated | Integrated | Unavailable (worldline not bundled) | Unavailable | +| Built-in worldline / WORLDLINE-R synthesis | Integrated | Integrated; page-size limitation below | Integrated | Integrated | Integrated in the native build; on-device synthesis still needs validation | Unavailable | | External UTAU resampler / wavtool programs | Conditional: matching Windows tools | No desktop executable compatibility guarantee | Native resamplers conditional; Windows tools experimental through Wine; native external wavtools unavailable | Native resamplers conditional; Windows tools experimental through Wine; native external wavtools unavailable | Unavailable | Unavailable | -| ONNX Runtime CPU inference | Integrated | Integrated (Android AAR) | Integrated | Integrated | Experimental | Unavailable in the current host | -| ONNX hardware acceleration | Conditional: DirectML | Conditional: NNAPI | Conditional: CUDA + cuDNN | Conditional: CoreML | Not exposed as an iOS accelerator by the current selector | Unavailable | +| ONNX Runtime CPU inference | Integrated | Integrated (Android AAR) | Integrated | Integrated | iOS XCFramework is packaged; model inference still needs device validation | Unavailable in the current host | +| ONNX hardware acceleration | Conditional: DirectML | Conditional: NNAPI | Conditional: CUDA + cuDNN | Conditional: CoreML | Conditional: CoreML; device validation pending | Unavailable | | DiffSinger / Vogen model-based synthesis | Conditional | Conditional | Conditional | Conditional | Experimental | Unavailable | | HifiSampler renderer | Conditional | Conditional | Conditional | Conditional | Experimental | Unavailable | -| GAME note extraction: ONNX | Conditional | Conditional | Conditional | Conditional | Unavailable (entry hidden) | Unavailable (entry hidden) | -| RMVPE pitch curve after note extraction | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Unavailable | Unavailable | -| GAME note extraction: GGML | Conditional, CPU | Conditional, CPU | Conditional, CPU | Conditional, CPU | Unavailable | Unavailable | +| GAME note extraction: ONNX | Conditional | Conditional | Conditional | Conditional | Conditional, CPU/CoreML; device validation pending | Unavailable (entry hidden) | +| RMVPE pitch curve after note extraction | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`); device validation pending | Unavailable | +| GAME note extraction: GGML | Conditional, CPU | Conditional, CPU | Conditional, CPU | Conditional, CPU | Unavailable (native runtime not packaged) | Unavailable | | GGML Vulkan / CUDA / Metal acceleration | Not delivered by default | Not delivered by default | Not delivered by default | Not delivered by default | Unavailable | Unavailable | | Voicebank / `.oudep` dependency installation | Integrated | Integrated; storage permission required | Integrated | Integrated | Experimental | Experimental filesystem integration | -| Additional Core engines (ENUNU, VOICEVOX, NEUTRINO) | Conditional; external engine required, not verified here | Not verified | Conditional; external engine required, not verified here | Conditional; external engine required, not verified here | Not verified | Not integrated | +| Additional Core engines (ENUNU, VOICEVOX, NEUTRINO) | Conditional; external engine required, not verified here | Not verified | Conditional; external engine required, not verified here | Conditional; external engine required, not verified here | ENUNU/VOICEVOX unavailable (local server); NEUTRINO ONNX conditional, runtime validation pending | Not integrated | Model-based renderers require the appropriate voicebank and auxiliary models. HifiSampler additionally requires its vocoder dependency package. A renderer appearing in the registry does not certify an external engine's @@ -111,7 +112,7 @@ See [desktop architecture and verification](docs/DESKTOP_UI.md) for implementati ### Hardware acceleration - **ONNX:** the current [provider selector](OpenUtau.Core/Util/Onnx.cs) offers DirectML on Windows, - NNAPI on Android, CoreML on macOS, and CUDA on Linux when CUDA and cuDNN are detected. + NNAPI on Android, CoreML on macOS and iOS, and CUDA on Linux when CUDA and cuDNN are detected. Availability also depends on the packaged ONNX Runtime, device drivers and model operators. Selecting a provider does not establish that every operation executes on the GPU/NPU or that it is faster than CPU. - **GAME ONNX:** uses this ONNX configuration. Its encoder explicitly uses CPU when CoreML is selected; @@ -150,6 +151,11 @@ Windows directories were also tested. Android APK checks confirm the expected GA These checks do **not** establish Android device inference, debugger attachment, GPU performance, or successful execution of all GitHub-hosted jobs. Check the actual workflow runs for CI results. +The iOS build workflow publishes an unsigned ARM64 IPA and verifies the package minimum OS, USTX document +type, background-audio declaration, and statically linked WORLDLINE archive. It does not boot an iOS simulator; +runtime behavior such as document import, audio routes, synthesis, and ONNX/CoreML inference must be checked +on an iPhone. + The new Android GAME libraries use 16 KB alignment. Existing dependencies can still emit `XA0141`: `libworldline.so` in the ARM64 build and `libSDL3.so` in the x64 build were observed with this warning. The whole APK is therefore not certified for 16 KB page-size devices. diff --git a/docs/CONTRIBUTING.en-US.md b/docs/CONTRIBUTING.en-US.md index 9b82e90c..9c1aea43 100644 --- a/docs/CONTRIBUTING.en-US.md +++ b/docs/CONTRIBUTING.en-US.md @@ -152,6 +152,39 @@ If compilation fails, inspect the first error and resolved SDK/NDK/JDK paths. A from a missing model; do not copy binaries from another RID. Use `GameBuildRoot` to isolate native build caches when needed. Check the [known limitations](../README.md#verification-and-known-limits), including Android 16 KB alignment warnings in existing dependencies. See the Chinese guide for the full troubleshooting table. +### 6. Build iOS on macOS + +The iOS project must be built on macOS with Xcode; a Windows build cannot replace the iOS SDK, simulator or +device validation. CI currently pins Xcode 27.0, .NET SDK 10.0.401 and workload set 10.0.401.1. From the +repository root, check `xcodebuild -version` and `dotnet --version`, then install the project workloads: + +```bash +export AVALONIA_TELEMETRY_OPTOUT=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +dotnet workload restore OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj --version 10.0.401.1 +``` + +Build the ARM64 and x64 simulator hosts: + +```bash +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-arm64 -p:EnableCodeSigning=false +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-x64 -p:EnableCodeSigning=false +``` + +Publish an unsigned ARM64 device IPA: + +```bash +dotnet publish OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r ios-arm64 \ + -p:EnableCodeSigning=false -p:BuildIpa=true -p:PublishAot=false -p:UseMonoRuntime=true \ + -p:MtouchUseLlvm=false -p:UseInterpreter=false -p:TrimMode=partial -p:MtouchLink=SdkOnly \ + -p:EnableAssemblyILStripping=false -p:_IsDedupEnabled=false +``` + +An unsigned IPA is useful for checking package contents, but it cannot be installed on a device until signed with +an Apple development identity and provisioning profile. Verify document import, playback through route changes +and interruptions, WORLDLINE synthesis and ONNX inference on a simulator or device before claiming runtime +support; a successful build only validates compilation and packaging. + --- ## Branches diff --git a/docs/PLATFORMS.md b/docs/PLATFORMS.md index 94eae970..ff702b36 100644 --- a/docs/PLATFORMS.md +++ b/docs/PLATFORMS.md @@ -45,14 +45,18 @@ Do not infer capability parity merely because hosts share App. RID-native files beside the executable for P/Invoke lookup. Preserve this during packaging changes; an assembly-only output is insufficient. - [iOS AppDelegate](../OpenUtauMobile.iOS/AppDelegate.cs) registers AVAudioEngine audio - initialization (with a Dummy fallback) and probes ONNX Runtime at startup. It does - not establish complete desktop/mobile feature parity. + initialization (with a Dummy fallback), probes ONNX Runtime at startup and receives + imported USTX documents. ONNX CPU and CoreML providers are available through the shared + runner selector and packaged iOS XCFramework; model execution still needs device validation. - iOS and Browser import the [Worldline native build](../native/worldline/README.md). Bazel produces static archives: iOS links them through `NativeReference` and resolves Core's `worldline` imports to explicitly retained main-program symbols; Browser uses - `NativeFileReference` with the .NET workload's Emscripten toolchain. This does not - provide GAME/ggml, ONNX support or a Browser audio output backend. iOS still requires - validation on macOS/Xcode and devices. + `NativeFileReference` with the .NET workload's Emscripten toolchain. Neither host + packages GAME/ggml; iOS GAME uses ONNX CPU, and Browser has no ONNX support or audio + output backend. iOS still requires validation on macOS/Xcode and devices. +- iOS excludes executable resamplers and wavtools that require `Process.Start`, and hides + ENUNU/VOICEVOX because they require a separate localhost server. In-process resamplers, + WORLDLINE and ONNX-based engines remain available subject to device validation. - [Browser Program](../OpenUtauMobile.Browser/Program.cs) uses silent Dummy audio and injects PathManager through private fields instead of its normal constructor. Core singleton/property changes therefore need browser diff --git a/native/worldline/README.md b/native/worldline/README.md index d4671fb5..733c6c39 100644 --- a/native/worldline/README.md +++ b/native/worldline/README.md @@ -12,7 +12,7 @@ - Android 使用 `../game/android-ndk-version.txt` 固定的 NDK r30,最低 API 24,支持四 ABI。 静态链接 libc++,要求 ELF LOAD 对齐至少 16 KB。`AndroidNdkDirectory` 显式路径优先,否则使用 SDK 中的固定版本。 - iOS 必须在 macOS 上安装完整 Xcode,支持 `ios-arm64`、`iossimulator-arm64`、`iossimulator-x64`。 - 使用所选 Xcode 的 Clang、ar 和对应 SDK;部署版本跟随宿主的 `SupportedOSPlatformVersion`(直接调用默认 15.0)。 + 使用所选 Xcode 的 Clang、ar 和对应 SDK;部署版本跟随宿主的 `SupportedOSPlatformVersion`(当前应用为 15.1,直接调用默认 15.0)。 - Browser 支持 `browser-wasm`,使用当前 .NET `wasm-tools` 工作负载中的 Emscripten、LLVM、Node 和 sysroot。 线程、SIMD 和异常模式由 MSBuild 传入,与最终 .NET WASM 链接配置一致,不额外安装独立 Emscripten。 From c934eb593fe06b73649f6edebb597f612250c466 Mon Sep 17 00:00:00 2001 From: MysticILD <173185810+MysticILD@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:20:40 +0200 Subject: [PATCH 2/4] fix: simplify project-open failure message --- OpenUtauMobile/Assets/Lang/Strings.en.resx | 2 +- OpenUtauMobile/Assets/Lang/Strings.ja.resx | 2 +- OpenUtauMobile/Assets/Lang/Strings.ru.resx | 2 +- OpenUtauMobile/Assets/Lang/Strings.uk.resx | 2 +- OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenUtauMobile/Assets/Lang/Strings.en.resx b/OpenUtauMobile/Assets/Lang/Strings.en.resx index 5b344c3a..c52c335b 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.en.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.en.resx @@ -515,7 +515,7 @@ Access to this folder is denied - OpenUtau Mobile could not import the selected USTX project. + Couldn't open the selected project. Go to parent folder diff --git a/OpenUtauMobile/Assets/Lang/Strings.ja.resx b/OpenUtauMobile/Assets/Lang/Strings.ja.resx index eacbb848..213c8fc7 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ja.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ja.resx @@ -515,7 +515,7 @@ このフォルダーへのアクセスが拒否されました - 選択した USTX プロジェクトを読み込めませんでした。 + 選択したプロジェクトを開けませんでした。 上のフォルダーへ移動 diff --git a/OpenUtauMobile/Assets/Lang/Strings.ru.resx b/OpenUtauMobile/Assets/Lang/Strings.ru.resx index 1db8f405..173c991f 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ru.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ru.resx @@ -444,7 +444,7 @@ Доступ к этой папке запрещён - Не удалось импортировать выбранный проект USTX. + Не удалось открыть выбранный проект. Перейти в родительскую папку diff --git a/OpenUtauMobile/Assets/Lang/Strings.uk.resx b/OpenUtauMobile/Assets/Lang/Strings.uk.resx index 2ec1c56a..1544c712 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.uk.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.uk.resx @@ -444,7 +444,7 @@ Доступ до цієї теки заборонено - Не вдалося імпортувати вибраний проєкт USTX. + Не вдалося відкрити вибраний проєкт. Перейти до батьківської теки diff --git a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx index a94a6eca..ff037d39 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx @@ -515,7 +515,7 @@ 无权访问此目录 - 无法导入所选的 USTX 工程。 + 无法打开所选工程。 返回上级目录 From 8f5a5f20b8ee0e3fe9e0f077b4c964c2933c333d Mon Sep 17 00:00:00 2001 From: vocoder712 <100213316+vocoder712@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:15:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20iOS=20=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E5=AF=BC=E5=85=A5=E4=B8=8E=E9=9F=B3=E9=A2=91=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenUtauMobile.iOS/AppDelegate.cs | 132 ++++++------------ OpenUtauMobile.iOS/Info.plist | 3 + .../Services/Audio/IosAudioOutput.cs | 24 +++- OpenUtauMobile/ViewModels/MainViewModel.cs | 35 ++--- README.md | 7 +- 5 files changed, 83 insertions(+), 118 deletions(-) diff --git a/OpenUtauMobile.iOS/AppDelegate.cs b/OpenUtauMobile.iOS/AppDelegate.cs index ef43c367..fe7d0829 100644 --- a/OpenUtauMobile.iOS/AppDelegate.cs +++ b/OpenUtauMobile.iOS/AppDelegate.cs @@ -5,9 +5,10 @@ using System.Threading.Tasks; using Foundation; using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media; +using Avalonia.Platform.Storage; using Avalonia.iOS; -using ObjCRuntime; using ReactiveUI.Avalonia; using Microsoft.ML.OnnxRuntime; using OpenUtau.Audio; @@ -49,121 +50,74 @@ protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) ServiceHub.GraphicsBackendService = graphicsService; return base.CustomizeAppBuilder(builder) .With(IosGraphicsBackendProvider.CreatePlatformOptions(graphicsService.StartupFallbackOrder)) + .AfterApplicationSetup(static appBuilder => + { + if (appBuilder.Instance?.TryGetFeature() is { } lifetime) + { + lifetime.Activated += OnAppActivated; + } + }) .UseReactiveUI(_ => { }); } /// - /// 接收文件提供程序交给应用打开的 USTX 工程。 + /// 接收 UIScene 在冷启动或运行期间交付的 USTX 工程。 /// - [Export("application:openURL:options:")] - public new bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) + private static async void OnAppActivated(object? sender, ActivatedEventArgs activation) { - if (!IsSupportedProjectUrl(url)) + if (activation is not FileActivatedEventArgs files) { - return base.OpenUrl(app, url, options); + return; } - _ = OpenProjectDocumentAsync(url); - return true; - } - - /// - /// 判断系统交给应用的文件是否为 USTX 工程。 - /// - private static bool IsSupportedProjectUrl(NSUrl url) - { - return url.IsFileUrl && - !string.IsNullOrEmpty(url.Path) && - string.Equals(Path.GetExtension(url.Path), ".ustx", StringComparison.OrdinalIgnoreCase); + foreach (IStorageItem item in files.Files) + { + using (item) + { + if (item is IStorageFile file && + string.Equals(Path.GetExtension(file.Name), ".ustx", StringComparison.OrdinalIgnoreCase)) + { + await OpenProjectDocumentAsync(file); + } + } + } } /// /// 在安全作用域仍有效时复制外部工程,并交给共享导航队列打开。 /// - private static async Task OpenProjectDocumentAsync(NSUrl url) + private static async Task OpenProjectDocumentAsync(IStorageFile file) { - bool hasSecurityScope = false; + string importDirectory = Path.Combine(PathManager.Inst.CachePath, "DocumentImports"); + string destinationPath = Path.Combine(importDirectory, $"{Guid.NewGuid():N}.ustx"); try { - hasSecurityScope = url.StartAccessingSecurityScopedResource(); - string localPath = await Task.Run(() => CopyProjectDocumentToCache(url)); - ExternalProjectOpenService.Enqueue(new ExternalProjectOpenRequest(localPath, DeleteSourceAfterRead: true)); - } - catch (Exception exception) - { - Log.Error(exception, "无法从 iOS 文件提供程序导入 USTX 工程"); - ExternalProjectOpenService.ReportFailure(exception); - } - finally - { - if (hasSecurityScope) + Directory.CreateDirectory(importDirectory); + await using (Stream source = await file.OpenReadAsync()) + await using (FileStream destination = File.Create(destinationPath)) { - url.StopAccessingSecurityScopedResource(); + await source.CopyToAsync(destination); } + ExternalProjectOpenService.Enqueue(new ExternalProjectOpenRequest(destinationPath, DeleteSourceAfterRead: true)); } - } - - /// - /// 协调读取系统文件提供程序中的工程,并复制到应用缓存。 - /// - private static string CopyProjectDocumentToCache(NSUrl sourceUrl) - { - if (string.IsNullOrEmpty(sourceUrl.Path)) + catch (Exception exception) { - throw new IOException(L.S("Ios.Document.ImportFailed")); - } - string importDirectory = Path.Combine(PathManager.Inst.CachePath, "DocumentImports"); - Directory.CreateDirectory(importDirectory); - string destinationPath = Path.Combine(importDirectory, $"{Guid.NewGuid():N}.ustx"); - - using NSFileCoordinator coordinator = new(null); - Exception? copyException = null; - coordinator.CoordinateRead( - sourceUrl, - NSFileCoordinatorReadingOptions.WithoutChanges, - out NSError? coordinationError, - coordinatedUrl => + Log.Error(exception, "无法从 iOS 文件提供程序导入 USTX 工程"); + try { - try + if (File.Exists(destinationPath)) { - string coordinatedPath = coordinatedUrl.Path - ?? throw new IOException(L.S("Ios.Document.ImportFailed")); - File.Copy(coordinatedPath, destinationPath); + File.Delete(destinationPath); } - catch (Exception exception) - { - copyException = exception; - try - { - if (File.Exists(destinationPath)) - { - File.Delete(destinationPath); - } - } - catch (Exception cleanupException) when (cleanupException is IOException or UnauthorizedAccessException) - { - // 保留原始复制异常,缓存目录由应用独占。 - } - } - }); - - if (coordinationError != null) - { - throw new IOException(coordinationError.LocalizedDescription); - } - if (copyException != null) - { - throw new IOException(L.S("Ios.Document.ImportFailed"), copyException); - } - - if (!File.Exists(destinationPath)) - { - throw new IOException(L.S("Ios.Document.ImportFailed")); + } + catch (Exception cleanupException) when (cleanupException is IOException or UnauthorizedAccessException) + { + Log.Warning(cleanupException, "无法清理 iOS 导入缓存 {Path}", destinationPath); + } + ExternalProjectOpenService.ReportFailure(new IOException(L.S("Ios.Document.ImportFailed"), exception)); } - - return destinationPath; } private static void InitPathManager() diff --git a/OpenUtauMobile.iOS/Info.plist b/OpenUtauMobile.iOS/Info.plist index ba6984f9..7865fbec 100644 --- a/OpenUtauMobile.iOS/Info.plist +++ b/OpenUtauMobile.iOS/Info.plist @@ -45,6 +45,9 @@ LSSupportsOpeningDocumentsInPlace + + UIApplicationSceneManifest + UIDeviceFamily 1 diff --git a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs index 982afa08..0feb3e04 100644 --- a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs +++ b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs @@ -131,25 +131,41 @@ public void Init(ISampleProvider provider) public void Play() { ThrowIfDisposed(); + PlaybackState previousState; + bool retryingInterruption; lock (syncRoot) { - if (sampleProvider == null || interruptionActive || - (playbackState == PlaybackState.Playing && engine.Running)) + if (sampleProvider == null || (playbackState == PlaybackState.Playing && engine.Running)) { return; } + previousState = playbackState; + retryingInterruption = interruptionActive; playbackState = PlaybackState.Playing; } try { StartEngine(); + if (retryingInterruption) + { + lock (syncRoot) + { + interruptionActive = false; + resumeAfterInterruption = false; + } + } } - catch + catch (Exception exception) { lock (syncRoot) { - playbackState = PlaybackState.Stopped; + playbackState = retryingInterruption ? previousState : PlaybackState.Stopped; + } + if (retryingInterruption && exception is InvalidOperationException) + { + Log.Warning(exception, "iOS 音频会话暂时无法恢复,保留中断前的播放请求"); + return; } throw; } diff --git a/OpenUtauMobile/ViewModels/MainViewModel.cs b/OpenUtauMobile/ViewModels/MainViewModel.cs index 7283f50f..7620e42a 100644 --- a/OpenUtauMobile/ViewModels/MainViewModel.cs +++ b/OpenUtauMobile/ViewModels/MainViewModel.cs @@ -274,34 +274,26 @@ private async Task OpenExternalProjectAsync(ExternalProjectOpenRequest request) try { NavigateViewModelBase source = CurrentViewModel; - if (source is SandboxFileManagerViewModel sandbox && - (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return; if (ServiceHub.UseDesktopFileWorkflows) { + if (source is SandboxFileManagerViewModel sandbox && + (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return; ProjectOpenKind kind = request.DeleteSourceAfterRead || !Path.GetExtension(request.LocalPath).Equals(".ustx", StringComparison.OrdinalIgnoreCase) ? ProjectOpenKind.ExternalCopy : ProjectOpenKind.Normal; sourceTransferred = await OpenDesktopProjectAsync(new(request.LocalPath, kind, request.DeleteSourceAfterRead)); return; } - if (CurrentViewModel is EditorViewModel currentEditor) - { - bool canExit = await currentEditor.ConfirmExitAsync(); - if (!canExit || CurrentViewModel != currentEditor) - { - return; - } + ProjectOpenOptions options = new(request.LocalPath, ProjectOpenKind.ExternalCopy, request.DeleteSourceAfterRead); + EditorViewModel.PreparedProject prepared = await EditorViewModel.PrepareProjectAsync(options); + if (CurrentViewModel != source || !await ConfirmCloseAsync() || CurrentViewModel != source) return; - // 替换编辑器时不激活栈中页面,避免它在下一帧启动后台工作。 - if (!TryRemoveCurrentViewModel(currentEditor, notifyRevealedViewModel: false)) - { - return; - } + // 连同覆盖在编辑器上的工具页一起移除,避免两个编辑器共用同一工程。 + while (ActiveEditor != null || CurrentViewModel is ISingerInstallationPage) + { + if (!TryRemoveCurrentViewModel(CurrentViewModel, notifyRevealedViewModel: false)) return; } - EditorViewModel editor = new(this, new ProjectOpenOptions( - request.LocalPath, - ProjectOpenKind.ExternalCopy, - request.DeleteSourceAfterRead)); + EditorViewModel editor = new(this, options, prepared); OnNavigate(editor); sourceTransferred = true; await editor.ProjectLoadCompletion; @@ -356,18 +348,19 @@ public void OnBackRequested() } /// - /// 确认桌面窗口是否可以关闭。 + /// 确认当前页面和工程是否可以关闭或被替换。 /// /// 当前工程允许退出时返回 true。 public async Task ConfirmCloseAsync() { - if (CurrentViewModel is ISingerInstallationPage setup) + NavigateViewModelBase source = CurrentViewModel; + if (source is ISingerInstallationPage setup) { if (!setup.TryLeave()) return false; await setup.CloseSessionAsync(); + if (CurrentViewModel != source) return false; } if (HasActiveSingerInstallation) return false; - NavigateViewModelBase source = CurrentViewModel; if (source is SandboxFileManagerViewModel sandbox && (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return false; if (ActiveEditor is EditorViewModel editorViewModel) diff --git a/README.md b/README.md index 2889bf29..abfe24a4 100644 --- a/README.md +++ b/README.md @@ -151,10 +151,9 @@ Windows directories were also tested. Android APK checks confirm the expected GA These checks do **not** establish Android device inference, debugger attachment, GPU performance, or successful execution of all GitHub-hosted jobs. Check the actual workflow runs for CI results. -The iOS build workflow publishes an unsigned ARM64 IPA and verifies the package minimum OS, USTX document -type, background-audio declaration, and statically linked WORLDLINE archive. It does not boot an iOS simulator; -runtime behavior such as document import, audio routes, synthesis, and ONNX/CoreML inference must be checked -on an iPhone. +The iOS build workflow publishes an unsigned ARM64 IPA and checks the minimum iOS version, USTX document +registration, and background-audio declaration in its `Info.plist`. Document import, audio routes, synthesis, +and ONNX/CoreML inference require device validation. The new Android GAME libraries use 16 KB alignment. Existing dependencies can still emit `XA0141`: `libworldline.so` in the ARM64 build and `libSDL3.so` in the x64 build were observed with this warning. From 76713c6f4283d8a590eba69b5cd90176c3272470 Mon Sep 17 00:00:00 2001 From: vocoder712 <100213316+vocoder712@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:55:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E5=85=B3=E9=97=AD=20iOS=20Mono=20?= =?UTF-8?q?=E8=A7=A3=E9=87=8A=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj index 871723a9..e61531e8 100644 --- a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj +++ b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj @@ -9,10 +9,10 @@ - + false false - OpenUtau.Plugin.Builtin,OpenUtau.Core + false partial false diff --git a/README.md b/README.md index abfe24a4..c2b92a58 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ is incomplete. **Unavailable** means the feature is not exposed or its required | Feature | Windows | Android | Linux | macOS | iOS | Browser | | --- | --- | --- | --- | --- | --- | --- | | Shared project / piano-roll editor | Integrated | Integrated | Integrated | Integrated | Experimental | Experimental | -| Built-in phonemizers | Integrated | Integrated | Integrated | Integrated | Experimental; Mono interpreter configured for reflection-created phonemizers, device validation pending | Experimental | +| Built-in phonemizers | Integrated | Integrated | Integrated | Integrated | Experimental; reflection-based creation under Mono AOT needs device validation | Experimental | | Desktop workspace, persistent inspectors and tool manager | Integrated; local checks below | Uses mobile presentation | Integrated; host verification pending | Integrated; host verification pending | Uses mobile presentation | Uses mobile presentation | | Audio playback | Integrated | Integrated | Integrated | Integrated | Experimental (AVAudioEngine) | Unavailable (Dummy output) | | Built-in worldline / WORLDLINE-R synthesis | Integrated | Integrated; page-size limitation below | Integrated | Integrated | Integrated in the native build; on-device synthesis still needs validation | Unavailable |