SwiftUI NowPlayingView on watchOS 7

Hi, I'm looking to add a Now Playing view to my new SwiftUI media app but I'm having trouble understanding how to navigate to this view. I've tried with NavigationLink but failed miserably.

If anyone could share a simple example of going from a starting ContentView to the NowPlayingView I'd really appreciate it!

The documentation for this new view is here: https://developer.apple.com/documentation/watchkit/nowplayingview

Thanks, and great WWDC20 so far!
Answered by Frameworks Engineer in 615234022
Hello!

NowPlayingView is available when you import both SwiftUI and WatchKit. It works just like any other SwiftUI view.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        NowPlayingView()
    }
}


You can push to it with a NavigationLink.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink("Show NowPlayingView", destination: NowPlayingView())
        }
    }
}


Or use a TabView to have it appear alongside other pages.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        TabView {
            NowPlayingView()
            Text("Page 2")
            Text("Page 3")
        }
    }
}


Accepted Answer
Hello!

NowPlayingView is available when you import both SwiftUI and WatchKit. It works just like any other SwiftUI view.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        NowPlayingView()
    }
}


You can push to it with a NavigationLink.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink("Show NowPlayingView", destination: NowPlayingView())
        }
    }
}


Or use a TabView to have it appear alongside other pages.

Code Block swift
import SwiftUI
import WatchKit
struct ContentView: View {
    var body: some View {
        TabView {
            NowPlayingView()
            Text("Page 2")
            Text("Page 3")
        }
    }
}


This worked perfectly, thank you!!
Not working here, submitted a feedback for it (FB8080765). Screen does appear, but no "Now Playing" info on it and the graphics are duplicated.
SwiftUI NowPlayingView on watchOS 7
 
 
Q