Learn Courses My Dashboard

Share Sheet in child

Hi, How do I show a share sheet in a child view. UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true, completion: nil) doesn’t work. Thanks in advanced!

Can you show more code about where this view is you want to present and describe what it looks like in your view hierarchy?

It is the direct child of the first loaded view. Here is the struct:

struct Guide: View {
    @State private var share = false
    var body: some View {
        NavigationView {
            ScrollView {
                VStack {
                    Group {
                        Text("Welcome")
                            .font(.headline)
                            .padding()
                        Text("Welcome to Pickt, the best way for a group of people (or a couple) can find a place to eat.")
                        Text("Create A Party")
                            .font(.headline)
                            .padding()
                        Text("To start searching, click \"Create Party\" and enter a neighboorhood, city, state or zip code in the search field (if you would like, you also can filter different styles. Then click create party. From there you can then share the generated code by telling someone or using the built in share button.")
                        Text("Join A Party")
                            .font(.headline)
                            .padding()
                        Text("If you have a code, click join code and enter the code you recieved. Note: ALL NAMES MUST BE DIFFERENT.")
                        Text("Picking Restaurants")
                            .font(.headline)
                            .padding()
                        Text("Next, swipe each restaurant card to the right for yes, and to the left for no. Pick your top restaurant. Then, finally, when everyone is done selecting their restaurants, the results will automatically show. To view more details about a restaurant just click on the row!")
                        Text("Other")
                            .font(.headline)
                            .padding()
                        Text("That's it! Easy peasy ketchup squeezy. For more help, click the get support putton below:")
                    }
                    .padding(.bottom)
                    Link(destination: URL(string: "mailto:pickt@mcrich23.com")!, label: {
                        Text("Get Support")
                        Image(systemName: "questionmark.circle")
                    })
                    Button(action: {
                        let text = "I found this great app called Pickt. It helps groups of people find a place to eat. You should download it here: https://apps.apple.com/us/app/pickt/id1584491007"
                               let activityVC = UIActivityViewController(activityItems: [text], applicationActivities: nil)
                               UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true, completion: nil)
                        share = true
                    }, label: {
                        Text("Share This App")
                        Image(systemName: "square.and.arrow.up")
                    })
                    .padding()
                }
                .padding()
            }
        }
        .navigationTitle("How To Guide")
        .navigationBarTitleDisplayMode(.large)
        .navigationViewStyle(StackNavigationViewStyle())
    }
}