Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,34 @@ jobs:

ls -lh "$IPA_PATH"

python - "$IPA_PATH" <<'PY'
import plistlib
import sys
from pathlib import PurePosixPath
from zipfile import ZipFile

with ZipFile(sys.argv[1]) as ipa:
plist_path = next(name for name in ipa.namelist()
if PurePosixPath(name).match("Payload/*.app/Info.plist"))
info = plistlib.loads(ipa.read(plist_path))

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

- name: Upload iOS Failure Diagnostics
if: failure()
uses: actions/upload-artifact@v4
Expand Down
34 changes: 33 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,39 @@ dotnet build OpenUtauMobile.Android/OpenUtauMobile.Android.csproj -r $androidRid
菜单名称可能随 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. 常见问题

| 现象 | 检查与处理 |
| --- | --- |
Expand Down
6 changes: 3 additions & 3 deletions OpenUtau.Core/Util/Onnx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static List<string> getRunnerOptions() {
runners.Add("DirectML");
}
return runners;
} else if (OS.IsMacOS()) {
} else if (OS.IsMacOS() || OS.IsIOS()) {
return new List<string> {
"CPU",
"CoreML"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
73 changes: 72 additions & 1 deletion OpenUtauMobile.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Foundation;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media;
using Avalonia.Platform.Storage;
using Avalonia.iOS;
using ReactiveUI.Avalonia;
using Microsoft.ML.OnnxRuntime;
Expand Down Expand Up @@ -47,15 +50,83 @@ 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<IActivatableLifetime>() is { } lifetime)
{
lifetime.Activated += OnAppActivated;
}
})
.UseReactiveUI(_ =>
{
});
}

/// <summary>
/// 接收 UIScene 在冷启动或运行期间交付的 USTX 工程。
/// </summary>
private static async void OnAppActivated(object? sender, ActivatedEventArgs activation)
{
if (activation is not FileActivatedEventArgs files)
{
return;
}

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);
}
}
}
}

/// <summary>
/// 在安全作用域仍有效时复制外部工程,并交给共享导航队列打开。
/// </summary>
private static async Task OpenProjectDocumentAsync(IStorageFile file)
{
string importDirectory = Path.Combine(PathManager.Inst.CachePath, "DocumentImports");
string destinationPath = Path.Combine(importDirectory, $"{Guid.NewGuid():N}.ustx");
try
{
Directory.CreateDirectory(importDirectory);
await using (Stream source = await file.OpenReadAsync())
await using (FileStream destination = File.Create(destinationPath))
{
await source.CopyToAsync(destination);
}
ExternalProjectOpenService.Enqueue(new ExternalProjectOpenRequest(destinationPath, DeleteSourceAfterRead: true));
}
catch (Exception exception)
{
Log.Error(exception, "无法从 iOS 文件提供程序导入 USTX 工程");
try
{
if (File.Exists(destinationPath))
{
File.Delete(destinationPath);
}
}
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));
}
}

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,
Expand Down
44 changes: 42 additions & 2 deletions OpenUtauMobile.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,50 @@
<dict>
<key>CFBundleDisplayName</key>
<string>OpenUtau Mobile 预览版</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>pers.vocoder712.openutaumobile.ustx</string>
<key>UTTypeDescription</key>
<string>OpenUtau Project</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>ustx</string>
</array>
<key>public.mime-type</key>
<string>application/x-openutau-project</string>
</dict>
</dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>OpenUtau Project</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>pers.vocoder712.openutaumobile.ustx</string>
</array>
</dict>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<!-- 场景配置由 AvaloniaAppDelegate 提供。 -->
<key>UIApplicationSceneManifest</key>
<dict/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
Expand All @@ -17,9 +57,9 @@
<string>LaunchScreen</string>
<key>UIFileSharingEnabled</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<key>UIBackgroundModes</key>
<array>
<string>armv7</string>
<string>audio</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
Expand Down
2 changes: 1 addition & 1 deletion OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-ios</TargetFramework>
<SupportedOSPlatformVersion>15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion>15.1</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Loading
Loading