Do we have any development allowance/tools for playback from Apple Music without a necessity to pay for the subscription?
Post
Replies
Boosts
Views
Activity
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?
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)
}
}
}
}