Unable to present. Please file a bug.

Hello I got an console error, while my view are back from NavigationLink. I looked for some solutions but this doesn't help me. Any ideas what generate this error? Application doesn't crash, but im interested in what provide this error.



Code Block
import SwiftUI
struct AddictionListView: View {
    @StateObject private var addictionListVM: AddictionListViewModel = AddictionListViewModel()
    init() {
        UINavigationBar.appearance().barTintColor = UIColor(named: "BackgroundMain")        
    }
    var body: some View {
        NavigationView {
            ZStack {
                Color("BackgroundMain").ignoresSafeArea(.all)
                ScrollView {
                    LazyVStack {
                        ForEach(addictionListVM.addictions) { addiction in
                            NavigationLink(destination: Text(addiction.name)) {
                                AddictionCellView(addiction: addiction)
                            }.buttonStyle(PlainButtonStyle())
                        }
                    }.padding()
                }
                VStack {
                    Spacer()
                    HStack {
                        Spacer()
                        NavigationLink(
                            destination: AddNewAddictionView(),
                            label: {
                                Image(systemName: "plus").foregroundColor(.white).font(.title)
                            })
                            .frame(width: 50, height: 50, alignment: .center)
                            .background(Color.green.opacity(0.8))
                            .clipShape(Circle())
                            .padding(25)
                    }
                }
            }
            .navigationBarTitle("Habit tracker!", displayMode: .inline)
        }
        .onAppear(perform: addictionListVM.createExampleAddictions)
    }
}

Answered by hower in 676694022

I also experienced the same issue using multiple NavigationLinks where on iPhone most times worked OK even though the error was displayed in the console but on iPad links would not work in most cases. I've solved it using tap gesture and a single navigation link. You can see the fix on Paul Hudson's site.

https://www.hackingwithswift.com/forums/swiftui/unable-to-present-please-file-a-bug/7901/8237

I'm seeing the same error - Unable to present. Please file a bug.

My setup is that I have a ParentView that has a NavigationLink that leads to ChildView. On the ChildView, I have a @StateObject view-model. And whenever something in ChildView changes and causes things to be rebuilt (repainted) in ParentView, I get this message Unable to present. Please file a bug.

My intuition tells me that at that moment, ChildView gets rebuilt as well, only keeping the @StateObject, and it does not properly get presented.

But I'm curious to find out what the "real" explanation and a possible solution is.

to track down the error, please show a reproducible example, in particular all your code related to "AddictionListViewModel" and "AddictionCellView"
Having the same issue with a similar setup others have mentioned. My setup is I use NavigationLink to go to another View. In there I'm using an ObservableObjectPublisher() to indicate changes have happened. Works fine in the simulator and my View gets updated. On my iPhone it kicks me out of the current View the NavigationLink took me to. If I remove the call to the ObservableObjectPublisher() the error isn't displayed but my View isn't updated.
Definitely something wrong with SwiftUI.

Here is a simple example that shows "Unable to present. Please file a bug." on iOS, and
does not work on Mac Catalyst.


Code Block
struct ContentView: View {
@State var arr = ["1","2","3"]
var body: some View {
NavigationView {
ScrollView {
ForEach(arr, id: \.self) { name in
NavigationLink(destination: Text("view \(name)")) {
Text("to view \(name)").padding(5)
}
}
}
}
}
}


The code I create is not a secret just an experiments. Below you can find the examples:

AddictionListViewModel
Code Block import Foundation
class AddictionListViewModel: ObservableObject {
    @Published var addictions = [Addiction]()
    
    
    func removeAddiction(at offset: IndexSet) {
        addictions.remove(atOffsets: offset)
    }
    
    func createExampleAddictions() {
        let yesterday = Calendar.current.date(byAdding: .day,value: -1, to: Date())!
        addictions.append(Addiction(id: 1,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 2,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 3,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 4,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 5,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 6,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 7,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 8,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 9,name: "example", dateStart: yesterday))
        addictions.append(Addiction(id: 10,name: "example", dateStart: yesterday))
    }
}

AddictionCellView
Code Block import Foundation
import SwiftUI
struct AddictionCellView: View {
    @ObservedObject var viewModel: AddictionCellViewModel
    
    var body: some View {
        GeometryReader { geometry in
            HStack {
                Circle().foregroundColor(Color("DetailGrey")).frame(width: geometry.size.width * 0.2).overlay(Text("99999999").aspectRatio(1,contentMode: .fit).lineLimit(2))
                VStack(alignment: .leading) {
                    Text(viewModel.addiction.name)
                        .lineLimit(1)
                        .font(.title)
                    Text("2012-01-01")
                        .font(.footnote)
                    Text("you saved now")
                        .font(.footnote)
                        .foregroundColor(Color("Citrine"))
                }
            }
            .padding()
        }
        .frame(height: 100)
        .background(Color("BackgroundCell").cornerRadius(25))
    }
}
struct AddictionCellView_Previews: PreviewProvider {
    static var previews: some View {
        AddictionCellView(addiction: Addiction(id: 1, name: "BednarzBednarzBednarz", dateStart: Date()))
    }
}
//MARK: - AddictionCellView init
extension AddictionCellView {
    init(addiction: Addiction) {
        self.viewModel = AddictionCellViewModel(addiction)
    }
}


Oh wow. I was going to use a TSI on this but after seeing that simple example I'm thinking otherwise.
I am seeing the same issue in my App. Multiple users already reported the bug to me and I am banging my head against the wall trying to figure this out.

Same Setup. NavigationLink in a Form view that is presenting a new Detail View and as soon as I call
Code Block
objectWillChange.send()

the view pops and I am directed back to the list view. Super annoying and causing quite a bit of frustration on my and my users end.
@bob_mosh, does your app work fine in the simulator? Mine does. You described almost exactly what I'm hitting.
@bob_mosh, @shitingsand, your issues may not be related to the original NavigationLink problem. Show us some example code, maybe we can track down your particular issues. In my example I tried all sorts of things, @State, @StateObjects, @ObservedObject, var, etc.. without any impact.
Same issue here:

Code Block
ForEach(collections, id:\.objectID) { collection in
        CollectionTile(collection: collection)
 }


does not work, or intermittently, throwing the error 'Unable to present, Please file a bug'.

I can work around it by changing ForEach into a List but then the UI is not exactly what I want.


I made a super simple test project to try and recreate it. Put it on my phone and it didn't happen. I then recompiled my app and put it on my phone and it didn't happen. The only difference between the last time I tried is that I upgraded Big Sur to 11.3.1.
Then uploaded a TestFlight and on that person's iPhone 11 the problem always happens. When I try to update the View it dismisses the current View reached via Navigationlink. I'm seriously confused.
yes it works with List, however even without ScrollView the message still shows, but it works on iPhone.
On Mac Catalyst, if I include StackNavigationViewStyle it shows the "error" but it works,
whereas without it it doesn't work at all. I'm now on macos 11.4 beta2, target ios 14.5, testing on ios 14.6 iPhone.

Code Block
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("view 1")) {
VStack{
Text("to view 1").padding(5)
}
}
NavigationLink(destination: Text("view 2")) {
VStack{
Text("to view 2").padding(5)
}
}
NavigationLink(destination: Text("view 3")) {
VStack{
Text("to view 3").padding(5)
}
}
}
}.navigationViewStyle(StackNavigationViewStyle()) // <---
}
}

I am dealing with the exact situation with no resolution from Apple.

App worked just fine (macOS parent-detail view type app), and then I upgraded to Big Sur 11.3, and it broke it.

Now clicking the parent NavigationLink gives me "unable to present" error and the behavior is absolutely erratic when I try to nail down any issue. Wasted hours only to find out others are having similar issues. I haven't found a workaround, and the app is dead for users with 11.3.

Really frustrating.
Same for me with erratic behavior. I upgraded to Big Sur 11.3.1 and didn't see it happen on my iPhone. Thinking it was fixed I made a TestFlight of the app I'm building and the first other iPhone I try it on has the problem. I had to expire the build and am still stuck.
Accepted Answer

I also experienced the same issue using multiple NavigationLinks where on iPhone most times worked OK even though the error was displayed in the console but on iPad links would not work in most cases. I've solved it using tap gesture and a single navigation link. You can see the fix on Paul Hudson's site.

https://www.hackingwithswift.com/forums/swiftui/unable-to-present-please-file-a-bug/7901/8237

Hi all - has anyone seen an actual fix for this issue? iPadOS 14.7 still exhibits this behavior in my apps. The multiple NavigationLinks in a single view appear to work on my iPhone app, but break on iPad and Mac Catalyst.

The EmptyView() workaround doesn't work for me. And I'm not interested in rewriting my entire navigation over this.

I've filed a bug, but haven't heard anything back from Apple. Has anyone heard back from the bugs they've filed?

This is super frustrating!

I tried to get a WWDC lab about this issue but the request was rejected.

I have the same problem for NavigationView with more than 2 NavigationLink. No problem with 1 ou 2 NavigationLink!

I had the same issue. Whenever the state of the ParentView is updated by some published property it messed up the navigation to the ChildView.

E.g.

LibraryView which can open BookViews and also download new books. During the download, the state is constantly updated (progress bar going 0-100). So whenever a book was downloading (continuous state updates of LibraryView), the NavigationLink messed up the navigation to BookView in one of two ways:

  1. popped the BookView from backstack immediately (like in https://developer.apple.com/forums/thread/677333) - this happened when I used just one NavigationLink and just changed its destination param depending on the current book.
  2. Yelled "Unable to present. Please file a bug." and caused the BookView to not properly register for its state changes on @Published viewmodel properties (so it was always stuck in "loading" state). - this happened when the NavigationLinks have been created inside ForEach.

The solution I used was to delegate the navigation to the viewmodel and stop listening to state changes there (cancel the Combine Publisher). Something like this:

    func navigateToBook(bookId: Int) {
        destinationBook = BookView(viewModel: createBookViewModel(bookId: Int(bookId)))
        cancellables.forEach { $0.cancel() }
        isBookPresented = true
    }

I honestly have no idea how to tie the lifecycle of viewModels to the lifecycle of SwiftUI views right now - NavigationLinks don't seem to be able to help, the onAppear / onDisappear are interleaved (i.e. the onAppear of ChildView will fire before onDisappear of ParentView).

It's a mess.

This problem finally stopped happening for me with the RC of Xcode and iOS 15.

Unable to present. Please file a bug.
 
 
Q