A cross platform Audiobookshelf client for Android and iOS
Dart
Log runtime App Group entitlement on iOS to diagnose widget profile issues
Barnabas929355eaf833
diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swiftindex 18582491..249c92be 100644--- a/ios/Runner/AppDelegate.swift+++ b/ios/Runner/AppDelegate.swift@@ -2,6 +2,7 @@ import Flutterimport UIKitimport AVFoundationimport MediaPlayer+import Securityimport just_audiolet flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadlessExecution: true)@@ -41,9 +42,23 @@ let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadl// Register platform channels on the shared engineregisterPlatformChannels()+ // Entitlement diagnostic: must run AFTER registerPlatformChannels so the+ // widget channel is available to forward logs into the Flutter LogService.+ logAppGroupEntitlement()+return super.application(application, didFinishLaunchingWithOptions: launchOptions)}+ /// Forwards a log line to the Dart LogService via the widget channel so it+ /// appears in the in-app log viewer (NSLog alone only shows in Xcode /+ /// Console.app on a Mac).+ private func logToFlutter(_ message: String) {+ NSLog("[WidgetDebug] %@", message)+ DispatchQueue.main.async { [weak self] in+ self?.widgetChannel?.invokeMethod("log", arguments: ["msg": message])+ }+ }+private func registerWidgetNotifications() {let center = CFNotificationCenterGetDarwinNotifyCenter()let observer = Unmanaged.passUnretained(self).toOpaque()@@ -81,6 +96,28 @@ let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadlNSLog("[WidgetDebug] AppDelegate registered %d Darwin notification observers", names.count)}+ /// Reads the actual runtime-effective entitlements from the app's code+ /// signature. If the App Group is listed here, the provisioning profile+ /// granted it. If not, the entitlements file is asking for something the+ /// profile doesn't provide - containerURL will return nil and the widget+ /// extension won't see shared UserDefaults writes.+ private func logAppGroupEntitlement() {+ guard let task = SecTaskCreateFromSelf(nil) else {+ logToFlutter("entitlements: SecTaskCreateFromSelf returned nil")+ return+ }+ let key = "com.apple.security.application-groups" as CFString+ var error: Unmanaged<CFError>?+ let value = SecTaskCopyValueForEntitlement(task, key, &error)+ if let groups = value as? [String] {+ logToFlutter("entitlements: application-groups granted by profile = [\(groups.joined(separator: ", "))]")+ } else if let err = error?.takeRetainedValue() {+ logToFlutter("entitlements: error reading application-groups: \(err)")+ } else {+ logToFlutter("entitlements: application-groups = <none> - provisioning profile does not grant any App Group (containerURL will be nil)")+ }+ }+private func registerPlatformChannels() {let messenger = flutterEngine.binaryMessengerdiff --git a/lib/services/home_widget_service.dart b/lib/services/home_widget_service.dartindex 107964ba..3e72d8e3 100644--- a/lib/services/home_widget_service.dart+++ b/lib/services/home_widget_service.dart@@ -52,7 +52,8 @@ class HomeWidgetService {debugPrint('[WidgetDebug] Failed to get group container path: $e');}- // Receive widget AppIntent actions forwarded from AppDelegate.+ // Receive widget AppIntent actions (and bridged Swift log lines)+ // forwarded from AppDelegate._widgetChannel.setMethodCallHandler((call) async {if (call.method == 'widgetAction') {final action = (call.arguments as Map?)?['action'] as String?;@@ -68,6 +69,9 @@ class HomeWidgetService {_handleSkipForward();break;}+ } else if (call.method == 'log') {+ final msg = (call.arguments as Map?)?['msg'] as String?;+ if (msg != null) debugPrint('[WidgetDebug] $msg');}return null;});