diff --git a/ios/Makefile b/ios/Makefile index 9f0bdd6..fbaada9 100644 --- a/ios/Makefile +++ b/ios/Makefile @@ -20,7 +20,7 @@ PROJECT := $(SPIKE)/SizzleSpike.xcodeproj SCHEME := SizzleSpike APP_ID := cc.tiredsysadmin.ios.sizzlespike BUILD_NO := $(shell sed -n 's/^ *CURRENT_PROJECT_VERSION: *"\(.*\)"/\1/p' $(SPIKE)/project.yml) -SOURCES := $(SPIKE)/project.yml $(wildcard $(SPIKE)/*/*.swift $(SPIKE)/*/*.plist $(SPIKE)/*/*.entitlements) +SOURCES := $(shell find $(SPIKE) -type f -not -path '*.xcodeproj/*') SIM_APP := build/sim/Build/Products/Debug-iphonesimulator/$(SCHEME).app DEV_APP := build/dev/Build/Products/Release-iphoneos/$(SCHEME).app diff --git a/ios/README.md b/ios/README.md index 11fc6aa..53f529b 100644 --- a/ios/README.md +++ b/ios/README.md @@ -12,7 +12,7 @@ App Groups work there? | Piece | What it is | |---|---| | `spike/project.yml` | XcodeGen spec; `make project` generates the Xcode project (git-ignored) | -| `spike/App/` | SwiftUI host app `cc.tiredsysadmin.ios.sizzlespike`; runs a self-test at launch | +| `spike/App/` | SwiftUI host app `cc.tiredsysadmin.ios.sizzlespike` with a self-test (Run self-test button) | | `spike/AU/` | App extension `…sizzlespike.au`: one AUv3 instrument (`aumu` / `sSpk` / `Tsys`), "Tired Sysadmin: Sizzle Spike Sine", a sine voice with a Gain parameter | | `spike/Shared/Spike.swift` | The App Group id, the component description, and the App Group probe both sides run | @@ -32,7 +32,7 @@ The self-test shows three checks: ### Build ```sh -make -C ios ipa # → ios/dist/cc.tiredsysadmin.ios.sizzlespike_1.ipa +make -C ios ipa # → ios/dist/cc.tiredsysadmin.ios.sizzlespike_.ipa ``` Needs Xcode and XcodeGen. The device build is unsigned, then ad-hoc signed inside-out @@ -47,9 +47,9 @@ runtime was installed when the spike was written, so it hasn't been run there. ### Test on the iPad -1. AirDrop or copy `cc.tiredsysadmin.ios.sizzlespike_1.ipa` to the iPad, open it with - TrollStore, install. -2. Open **Sizzle Spike** and note [1]–[3] (screenshot the screen). +1. AirDrop or copy the newest `cc.tiredsysadmin.ios.sizzlespike_.ipa` to the + iPad, open it with TrollStore, install. +2. Open **Sizzle Spike**, tap **Run self-test**, and note [1]–[3] (screenshot). 3. In AUM (or GarageBand → Audio Units, Loopy, Drambo…), add an instrument and look for **Tired Sysadmin: Sizzle Spike Sine**. Load it, play notes, open its view (it lists the App Group files). @@ -66,6 +66,22 @@ What the outcomes mean: passing sample data through the plugin's saved state, or having the plugin pick files with a document picker. +### Results so far + +- **Build 1 (0.1.0):** AUM lists the plugin, loads it, and it plays from a MIDI + keyboard, so hosts do see AUv3 plugins from a TrollStore install. AUM showed a + red X as its icon (the app had no icon), and the app itself closed right after + opening (it ran the self-test at launch). +- **Build 2 (0.1.1):** adds an app icon, the SwiftUI scene manifest, and makes the + self-test crash-proof for diagnosis. It runs only on the button. Each step is + saved before it runs, so the next launch says where a crash happened + ("The previous run stopped during: …"). AVAudioEngine's Objective-C exceptions + are caught by `App/ObjC/SPKTry.m` and printed instead of killing the app. + +If the app still closes before showing anything, the crash is at launch. Its log +is in Settings → Privacy & Security → Analytics & Improvements → Analytics Data, +in a file named `SizzleSpike-.ips`. + ## Decisions - **XcodeGen, not a checked-in .xcodeproj:** the project is text you can diff and diff --git a/ios/spike/App/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios/spike/App/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..df8b22a --- /dev/null +++ b/ios/spike/App/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,6 @@ +{ + "images" : [ + { "filename" : "icon-1024.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" } + ], + "info" : { "author" : "xcode", "version" : 1 } +} diff --git a/ios/spike/App/Assets.xcassets/AppIcon.appiconset/icon-1024.png b/ios/spike/App/Assets.xcassets/AppIcon.appiconset/icon-1024.png new file mode 100644 index 0000000..a2ed9b5 Binary files /dev/null and b/ios/spike/App/Assets.xcassets/AppIcon.appiconset/icon-1024.png differ diff --git a/ios/spike/App/Assets.xcassets/Contents.json b/ios/spike/App/Assets.xcassets/Contents.json new file mode 100644 index 0000000..46cba7d --- /dev/null +++ b/ios/spike/App/Assets.xcassets/Contents.json @@ -0,0 +1 @@ +{ "info" : { "author" : "xcode", "version" : 1 } } diff --git a/ios/spike/App/Bridging.h b/ios/spike/App/Bridging.h new file mode 100644 index 0000000..a0863f7 --- /dev/null +++ b/ios/spike/App/Bridging.h @@ -0,0 +1 @@ +#import "ObjC/SPKTry.h" diff --git a/ios/spike/App/ContentView.swift b/ios/spike/App/ContentView.swift index 5bb586d..7d22ddd 100644 --- a/ios/spike/App/ContentView.swift +++ b/ios/spike/App/ContentView.swift @@ -25,6 +25,5 @@ struct ContentView: View { } .padding() .preferredColorScheme(.dark) - .task { await test.run() } } } diff --git a/ios/spike/App/ObjC/SPKTry.h b/ios/spike/App/ObjC/SPKTry.h new file mode 100644 index 0000000..8b77e79 --- /dev/null +++ b/ios/spike/App/ObjC/SPKTry.h @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown +// SPDX-License-Identifier: GPL-3.0-or-later + +#import + +NS_ASSUME_NONNULL_BEGIN + +/// Runs `block`, turning an Objective-C exception (AVAudioEngine raises them for +/// misuse, and Swift can't catch them, so they crash the app) into a returned +/// description. Returns nil when the block finished normally. +NSString *_Nullable SPKTry(NS_NOESCAPE void (^block)(void)); + +NS_ASSUME_NONNULL_END diff --git a/ios/spike/App/ObjC/SPKTry.m b/ios/spike/App/ObjC/SPKTry.m new file mode 100644 index 0000000..759740e --- /dev/null +++ b/ios/spike/App/ObjC/SPKTry.m @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown +// SPDX-License-Identifier: GPL-3.0-or-later + +#import "SPKTry.h" + +NSString *_Nullable SPKTry(NS_NOESCAPE void (^block)(void)) { + @try { + block(); + return nil; + } @catch (NSException *e) { + return [NSString stringWithFormat:@"%@: %@", e.name, e.reason ?: @"(no reason)"]; + } +} diff --git a/ios/spike/App/SelfTest.swift b/ios/spike/App/SelfTest.swift index 5f7e80d..7ad296a 100644 --- a/ios/spike/App/SelfTest.swift +++ b/ios/spike/App/SelfTest.swift @@ -8,68 +8,116 @@ import os /// 1. did iOS register the extension's Audio Unit (what hosts will list)? /// 2. does it load out of process and render sound? /// 3. can the app and the extension share files through the App Group? +/// +/// Runs only when asked (not at launch), records each step in UserDefaults before +/// doing it, and routes AVAudioEngine calls through SPKTry, so a crash or an +/// Objective-C exception leaves a readable trail instead of a vanishing app. @MainActor final class SelfTest: ObservableObject { @Published var lines: [String] = [] private let log = Logger(subsystem: "cc.tiredsysadmin.ios.sizzlespike", category: "selftest") + private let defaults = UserDefaults.standard + private static let stepKey = "selftest.step" private var liveEngine: AVAudioEngine? + init() { + lines = ["iOS \(ProcessInfo.processInfo.operatingSystemVersionString)", + "App started OK."] + if let step = defaults.string(forKey: Self.stepKey) { + lines.append("!! The previous run stopped during: \(step)") + } + lines.append("Tap Run self-test.") + } + private func say(_ s: String) { lines.append(s) log.notice("\(s, privacy: .public)") } + /// Remember what we're about to do; cleared when the run finishes. + private func step(_ s: String) { + defaults.set(s, forKey: Self.stepKey) + defaults.synchronize() + } + + /// Runs an AVAudioEngine call, reporting an Objective-C exception as a failure. + private func objc(_ what: String, _ body: () -> Void) -> Bool { + step(what) + if let ex = SPKTry(body) { say(" \(what): EXCEPTION \(ex)"); return false } + return true + } + func run() async { - lines = [] - let os = ProcessInfo.processInfo.operatingSystemVersionString - say("iOS \(os)") + lines = ["iOS \(ProcessInfo.processInfo.operatingSystemVersionString)"] // 1. Registration + step("[1] component lookup") let all = AVAudioUnitComponentManager.shared().components(matching: Spike.desc) say("[1] Registered components matching Tsys/sSpk: \(all.count) \(all.isEmpty ? "FAIL" : "PASS")") for c in all { say(" \(c.name) v\(c.versionString), type \(c.typeName)") } // 3a. App Group from the app side (before the AU writes) + step("[3] App Group probe") say("[3] " + Spike.probeGroup(as: "app")) // 2. Load out of process, render 1 s offline (silent), measure the peak do { + step("[2] instantiate out of process") let unit = try await AVAudioUnit.instantiate(with: Spike.desc, options: .loadOutOfProcess) say("[2] Instantiated \"\(unit.auAudioUnit.audioUnitName ?? "?")\" out of process: PASS") let engine = AVAudioEngine() let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)! - try engine.enableManualRenderingMode(.offline, format: format, maximumFrameCount: 4096) - engine.attach(unit) - engine.connect(unit, to: engine.mainMixerNode, format: format) - try engine.start() - (unit as? AVAudioUnitMIDIInstrument)?.startNote(69, withVelocity: 100, onChannel: 0) + var thrown: Error? + guard objc("[2] enable offline rendering", { + do { try engine.enableManualRenderingMode(.offline, format: format, maximumFrameCount: 4096) } + catch { thrown = error } + }), thrown == nil else { throw thrown ?? SpikeError.exception } + guard objc("[2] connect", { + engine.attach(unit) + engine.connect(unit, to: engine.mainMixerNode, format: format) + }) else { throw SpikeError.exception } + guard objc("[2] start engine", { do { try engine.start() } catch { thrown = error } }), thrown == nil + else { throw thrown ?? SpikeError.exception } + guard objc("[2] note on", { (unit as? AVAudioUnitMIDIInstrument)?.startNote(69, withVelocity: 100, onChannel: 0) }) + else { throw SpikeError.exception } let buf = AVAudioPCMBuffer(pcmFormat: engine.manualRenderingFormat, frameCapacity: 4096)! var peak: Float = 0 for _ in 0..<11 { - _ = try engine.renderOffline(4096, to: buf) - let ch = buf.floatChannelData![0] - for i in 0.. 0.05 ? "PASS" : "FAIL")) } catch { say("[2] FAIL: \(error.localizedDescription) (\((error as NSError).code))") } // 3b. The AU wrote au.txt when it was created; read it back from the app side + step("[3] App Group probe after AU load") say("[3] after AU load: " + Spike.probeGroup(as: "app")) + defaults.removeObject(forKey: Self.stepKey) + say("Done.") } /// Audible check through the speaker, using the same out-of-process AU. func playTone() async { do { + step("play: audio session") try AVAudioSession.sharedInstance().setCategory(.playback) try AVAudioSession.sharedInstance().setActive(true) + step("play: instantiate") let unit = try await AVAudioUnit.instantiate(with: Spike.desc, options: .loadOutOfProcess) let engine = AVAudioEngine() - engine.attach(unit) - engine.connect(unit, to: engine.mainMixerNode, format: nil) - try engine.start() + var thrown: Error? + guard objc("play: connect + start", { + engine.attach(unit) + engine.connect(unit, to: engine.mainMixerNode, format: nil) + do { try engine.start() } catch { thrown = error } + }), thrown == nil else { throw thrown ?? SpikeError.exception } liveEngine = engine let inst = unit as? AVAudioUnitMIDIInstrument inst?.startNote(69, withVelocity: 100, onChannel: 0) @@ -78,9 +126,15 @@ final class SelfTest: ObservableObject { try await Task.sleep(nanoseconds: 300_000_000) engine.stop() liveEngine = nil + defaults.removeObject(forKey: Self.stepKey) say("Played A4 for 1 s") } catch { say("Play FAIL: \(error.localizedDescription)") } } } + +enum SpikeError: LocalizedError { + case exception + var errorDescription: String? { "Objective-C exception (see the line above)" } +} diff --git a/ios/spike/project.yml b/ios/spike/project.yml index 14ed733..71162eb 100644 --- a/ios/spike/project.yml +++ b/ios/spike/project.yml @@ -8,8 +8,8 @@ options: iOS: "15.0" settings: base: - MARKETING_VERSION: "0.1.0" - CURRENT_PROJECT_VERSION: "1" + MARKETING_VERSION: "0.1.1" + CURRENT_PROJECT_VERSION: "2" SWIFT_VERSION: "5.0" TARGETED_DEVICE_FAMILY: "1,2" ARCHS: arm64 @@ -30,9 +30,11 @@ targets: GENERATE_INFOPLIST_FILE: YES INFOPLIST_KEY_CFBundleDisplayName: Sizzle Spike INFOPLIST_KEY_UILaunchScreen_Generation: YES + INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES + ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon + SWIFT_OBJC_BRIDGING_HEADER: App/Bridging.h INFOPLIST_KEY_UISupportedInterfaceOrientations: "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight" INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad: "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight" - INFOPLIST_KEY_UIBackgroundModes: audio SizzleSpikeAU: type: app-extension platform: iOS