I am working on an app that I would like to provide a welcome screen when launched. Not a Launch Screen in iOS, but more of a welcome screen that you see after an app has updated to a new version. Does anyone know how apple does this with their apps? Do they use a Sheet View that's tied to a version number? I have attached a couple of screen shots of when I opened Keynote after it updated. Any help on where to start would be much appreciated.
SwiftUI Welcome View
Hi @ChuckVJr , I assume your app is a Mac app? A great way to go about this is using sheet like this:
import SwiftUI
struct ContentView: View {
@AppStorage("firstTime") var firstTime: Bool = true
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.sheet(isPresented: $firstTime) {
VStack {
Text("Welcome")
Rectangle().fill(.white)
Button("dismiss") {
firstTime = false
}
}
.padding()
}
}
}
Here, I'm using the @AppStorage
property wrapper to save the variable firstTime
to User Defaults so the app saves the value for the next launch. When the variable is true, as it's set to be on the first launch, the sheet will be shown. When the user dismisses the sheet, the variable is set to false (which is written to User Defaults) so the sheet will not be opened on the next launch.