Post

Replies

Boosts

Views

Created

`NewDocumentButton(contentType:)` gives "Content serialization failed, document won't be saved."
I'm working on an iOS document-based app. It uses ReferenceFileDocument and custom creation of documents via DocumentGroupLaunchScene + NewDocumentButton. It works fine when I use the plain NewDocumentButton("Whatever") (without any more arguments), but when I want to perform additional setup via preapreDocumentURL or even just add a contentType it gives such output in the console when I hit it: Content serialization failed, document won't be saved. UTType.replayable is correctly wired up in the plist. It looks like a bug in the SDK, but maybe there is a chance that I'm doing something wrong? Here's a code: import SwiftUI import UniformTypeIdentifiers import Combine @main struct MyApp: App { var body: some Scene { DocumentGroup { Document() } editor: { documentConfiguration in EmptyView() } DocumentGroupLaunchScene("Yoyo") { NewDocumentButton(contentType: .replayable) { return URL(string: "whatever, it doesnt even go there...")! } } } } final class Document: ReferenceFileDocument { static var readableContentTypes: [UTType] { [.replayable] } @Published var x = 0 init() {} init(configuration: ReadConfiguration) throws {} func snapshot(contentType: UTType) throws -> Data { Data() } func fileWrapper(snapshot: Data, configuration: WriteConfiguration) throws -> FileWrapper { .init(regularFileWithContents: snapshot) } } extension UTType { static var replayable: UTType { UTType(exportedAs: "com.whatever.yo") } }
2
0
73
Nov ’25
ApplicationMusicPlayer plays music while app is in background
Taking the reference I expected the ApplicationMusicPlayer in my app to pause as soon as I go to the background. It doesn't happen in my app (I don't have any background modes configured for my app). Also - the playback status and queue is not visible in the Apple Music app, butits visible and controllable with the Apple Music Widgets. Is this actually a bug or I'm doing something obviously wrong? Or everything works as expected and I just don't understand/overinterpret something? Code: @main struct SoundMarkerApp: App {   @Environment(\.scenePhase) var scenePhase       var body: some Scene {     DocumentGroup(newDocument: SongDocument()) { file in       Text("V")         .onAppear {           Task {             do {               let player = ApplicationMusicPlayer.shared                               let searchRequest = MusicCatalogResourceRequest<Song>(                 matching: \.id,                 equalTo: MusicItemID("254945856")               )               let searchResponse = try await searchRequest.response()               player.queue = [searchResponse.items.first!]               try await player.prepareToPlay()               try await player.play()             }           }         }         .onChange(of: scenePhase) { newValue in           print(newValue)         }     }   } }
0
0
944
Sep ’22
SwiftUI, NavigationLink and UndoManager
I'm trying to access UndoManager via Environment somewhere deep in the navigation hierarchy: import SwiftUI @main struct TestUndoManagerEnvironmentApp: App {   var body: some Scene {     DocumentGroup(newDocument: TestUndoManagerEnvironmentDocument()) { file in       WrapperContent()     }   } } struct WrapperContent: View {   @Environment(\.undoManager) private var undoManager: UndoManager!   var body: some View {     NavigationLink(destination: ContentView()) {       Text("go")     }     Text("\(undoManager.canRedo ? "t" : "f")")   } } struct ContentView: View {   @Environment(\.undoManager) private var undoManager: UndoManager!   var body: some View {     Text("\(undoManager.canRedo ? "t" : "f")")   } } And whenever I run the app I get the Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value in ContentView.body. Am I doing something clearly wrong?
0
0
676
Sep ’22