Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Guard native player registration on iOS 16+

Barnabas8f95f5aa51b5
diff --git a/ios/AbsorbPlayerCore/Sources/AbsorbPlayerCore/AbsorbPlayerCoreProtocol.swift b/ios/AbsorbPlayerCore/Sources/AbsorbPlayerCore/AbsorbPlayerCoreProtocol.swift
index 63a06967..a09eff31 100644
--- a/ios/AbsorbPlayerCore/Sources/AbsorbPlayerCore/AbsorbPlayerCoreProtocol.swift
+++ b/ios/AbsorbPlayerCore/Sources/AbsorbPlayerCore/AbsorbPlayerCoreProtocol.swift
@@ -6,7 +6,7 @@ import Foundation
/// and the host app's AppDelegate registers a concrete singleton via
/// `AppDependencyManager.shared.add(dependency:)`. This is what tells iOS to
/// run the intent in the host app's process rather than the widget extension
-/// process — without that, the widget's `perform()` can't reach the audio
+/// process - without that, the widget's `perform()` can't reach the audio
/// engine that lives in the host app.
public protocol AbsorbPlayerCoreProtocol: Sendable {
func play()
diff --git a/ios/NowPlayingWidget/NowPlayingWidget.swift b/ios/NowPlayingWidget/NowPlayingWidget.swift
index 1287e70f..38a9f887 100644
--- a/ios/NowPlayingWidget/NowPlayingWidget.swift
+++ b/ios/NowPlayingWidget/NowPlayingWidget.swift
@@ -64,7 +64,7 @@ struct PlayPauseIntent: AudioPlaybackIntent {
static var description = IntentDescription("Toggle audiobook playback.")
/// Declaring this dependency tells iOS to launch the host app's process
- /// to run perform() — the AppDependencyManager registration lives in
+ /// to run perform() - the AppDependencyManager registration lives in
/// Runner's AppDelegate. Without this the intent runs in the widget
/// extension's sandbox where it can't drive audio.
@Dependency
@@ -72,7 +72,7 @@ struct PlayPauseIntent: AudioPlaybackIntent {
func perform() async throws -> some IntentResult {
// Routing through core.log lands the line in absorb's in-app log
- // viewer (via the widget channel's "log" method) — that's how we
+ // viewer (via the widget channel's "log" method), that's how we
// verify Phase 1 without needing Xcode console access.
core.log("[NativeCore] PlayPauseIntent.perform fired (host process)")
// Optimistic UI: flip the stored state so the widget redraws immediately.
diff --git a/ios/Runner/AbsorbPlayerCore.swift b/ios/Runner/AbsorbPlayerCore.swift
index 8240a628..fc045511 100644
--- a/ios/Runner/AbsorbPlayerCore.swift
+++ b/ios/Runner/AbsorbPlayerCore.swift
@@ -4,7 +4,7 @@ import Foundation
/// Phase 1 stub. Each call gets logged twice: NSLog (visible in Xcode /
/// Console.app on a Mac) AND through `logSink` which AppDelegate wires to
/// the Flutter widget channel's "log" method so it lands in the in-app log
-/// viewer. That second path is what we actually rely on for verification —
+/// viewer. That second path is what we actually rely on for verification,
/// no Mac needed.
///
/// Once we see `[NativeCore] toggle() called` show up in absorb's in-app
diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift
index 016426ed..55ba5330 100644
--- a/ios/Runner/AppDelegate.swift
+++ b/ios/Runner/AppDelegate.swift
@@ -54,15 +54,21 @@ let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadl
}
// Register the native player core as an AppIntent dependency. The widget
- // intent declares `@Dependency var core: AbsorbPlayerCoreProtocol` — that
+ // intent declares `@Dependency var core: AbsorbPlayerCoreProtocol` - that
// signals to iOS to launch this host app process to run the intent's
// perform(), and the dependency manager hands back this concrete instance
// so the intent can drive audio in-process. Without this, the widget
// intent runs in the widget extension's sandbox and can't reach our audio
// engine.
- let core: AbsorbPlayerCoreProtocol = AbsorbPlayerCore.shared
- AppDependencyManager.shared.add(dependency: core)
- AbsorbPlayerCore.logSink?("[NativeCore] Registered as AppIntent dependency")
+ //
+ // AppIntents (and AppDependencyManager) are iOS 16+. Runner ships back
+ // to iOS 15 so we have to guard the call. iOS 15 users won't have the
+ // widget anyway (widget extension's deployment target is iOS 17).
+ if #available(iOS 16.0, *) {
+ let core: AbsorbPlayerCoreProtocol = AbsorbPlayerCore.shared
+ AppDependencyManager.shared.add(dependency: core)
+ AbsorbPlayerCore.logSink?("[NativeCore] Registered as AppIntent dependency")
+ }
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}