iOS spike build 2: app icon, scene manifest, crash-proof self-test on demand

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-14 20:28:29 +01:00
co-authored by Claude Opus 5.5
parent 77d6e459b2
commit c9ad186de1
11 changed files with 130 additions and 25 deletions
@@ -0,0 +1,6 @@
{
"images" : [
{ "filename" : "icon-1024.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" }
],
"info" : { "author" : "xcode", "version" : 1 }
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@@ -0,0 +1 @@
{ "info" : { "author" : "xcode", "version" : 1 } }
+1
View File
@@ -0,0 +1 @@
#import "ObjC/SPKTry.h"
-1
View File
@@ -25,6 +25,5 @@ struct ContentView: View {
}
.padding()
.preferredColorScheme(.dark)
.task { await test.run() }
}
}
+13
View File
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
#import <Foundation/Foundation.h>
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
+13
View File
@@ -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)"];
}
}
+69 -15
View File
@@ -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..<Int(buf.frameLength) { peak = max(peak, abs(ch[i])) }
guard objc("[2] render", {
do { _ = try engine.renderOffline(4096, to: buf) } catch { thrown = error }
}), thrown == nil else { throw thrown ?? SpikeError.exception }
if let ch = buf.floatChannelData?[0] {
for i in 0..<Int(buf.frameLength) { peak = max(peak, abs(ch[i])) }
}
}
engine.stop()
_ = objc("[2] stop engine") { engine.stop() }
say(String(format: "[2] Rendered 1 s offline, peak %.3f: %@", peak, peak > 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)" }
}
+5 -3
View File
@@ -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