Button not dismissing Onboarding Modal

Hello all,

My app has a welcome screen that only displays when the app is first launched. I'm doing this using @AppStorage property wrapper. It is set to true initially, which triggers the .sheet(isPresented:) modal view. In the modal view, there is a button that users can press to dismiss the modal view. This button sets a binding variable to false, which in turn should change the AppStorage variable to false. Problem is, the button, when pressed, doesn't dismiss the modal. Please see code below:

This is the modal view:

Code Block
struct IntroductionView: View {
    @Binding var isShowingIntroScreen: Bool
    var body: some View {
            VStack {
                Spacer()
                    .frame(height: 20)
                ScrollView {
                TitleView()
                Spacer()
                InformationContainerView()
                Spacer()
                }
                    Button(action: {
                        self.isShowingIntroScreen = false
                        print(123)
                        }
                    ) {
                        Text("Get started")
                            .customButton()
                    }
                .padding()
                Spacer()
                    .frame(height: 0)
            }
    }
}


This is the content view:

Code Block
struct ContentView: View {
@AppStorage("Onboarding View") var isShowingOnboardingScreen = true
var body: some View {
.background(EmptyView()
                .sheet(isPresented: $isShowingOnboardingScreen, content: { IntroductionView(isShowingIntroScreen: $isShowingOnboardingScreen)
                  })
          )


When I press the button in the modal view, it prints 123 but doesn't dismiss the modal. Am I doing something wrong?
Answered by OOPer in 663905022
I have tested your project on my iPhone 7 plus (iOS 14.3)/iPhone 12 Max (iOS 14.4), and both work as expected as I wrote in my former post.

I needed to change Bundle Identifier and remove Capabilities: iCloud and Push Notification to test the app on my testing account. And I needed to Trust my testing account, each time I deleted the app. Any of such things may be affecting.

So, I think your code is well, just your testing environment or something other than code may be affecting.

after that, the button stopped working, if you'll believe it. 

If that is an observable fact, we should think based on it. But as for now, I have no clue what's causing the issue.


I recommend you, again, to create another brand-new project. Move some code from your actual project to it one by one , until you can reproduce the issue. (You may need to modify your project settings and code to make it build and run with the limited resources for each step.) That may reveal what may be affecting.

When I press the button in the modal view, it prints 123 but doesn't dismiss the modal.

As far as I tried, when I press the button in the modal view, it does print 123 and does dismiss the modal.
(Sorry, corrected.)

Maybe something hidden in your code is affecting. Better show issue reproducible code.
Source code here. (Github) To recreate, just run the program and try to click "Get Started"
Files are in 'IntroductionView.swift' and 'ContentView.swift' Find the code for showing the modal on lines 106 and 208 of ContentView.
I tried your project,
(You should better create a simplified project and include all the code into your post. Not many readers will go into the links.)
  • Notification alert appears

  • Welcome to Meetings sheet is shown below the alert

Whether I choose Allow or Don't Allow
  • Welcome to Meetings sheet gets visible

I tap Get started
  • Sheet changes to What's New to Meetings

I tap Continue
  • Sheet dismissed, and a view with navigation title My Meetings appears

Quite as expected.

Is there any condition to reproduce the issue? Any specific iOS versions? Need actual device?

Seems like it might have been an error with Xcode. I just tried using the simulator, and it works fine. I was using my personal device and deleting the app each time. That might have something to do with the app storage property, I don't know. Do you know if deleting an app from the device actually resets the app storage properties? The 'Welcome to Meetings' still shows up, but the 'get started' button doesn't work.

 Do you know if deleting an app from the device actually resets the app storage properties?

AppStorage should be deleted when you delete your App.
I will try later using some actual devices.
Thank you. It worked the first time after I deleted the app from my actual device and ran the project, but after that, the button stopped working, if you'll believe it.
Accepted Answer
I have tested your project on my iPhone 7 plus (iOS 14.3)/iPhone 12 Max (iOS 14.4), and both work as expected as I wrote in my former post.

I needed to change Bundle Identifier and remove Capabilities: iCloud and Push Notification to test the app on my testing account. And I needed to Trust my testing account, each time I deleted the app. Any of such things may be affecting.

So, I think your code is well, just your testing environment or something other than code may be affecting.

after that, the button stopped working, if you'll believe it. 

If that is an observable fact, we should think based on it. But as for now, I have no clue what's causing the issue.


I recommend you, again, to create another brand-new project. Move some code from your actual project to it one by one , until you can reproduce the issue. (You may need to modify your project settings and code to make it build and run with the limited resources for each step.) That may reveal what may be affecting.
Thank you for taking the time to do that. As you suggested, I will try to merge some code with a new project.
Button not dismissing Onboarding Modal
 
 
Q