Wednesday, January 31, 2024
HomeiOS Developmentios - "Publishing adjustments from background threads isn't allowed" after launching a...

ios – “Publishing adjustments from background threads isn’t allowed” after launching a browser and returning to the app


I’ve a SwiftUI (document-based) app utilizing Swift Knowledge, working on an iPhone 13 with iOS 17.2. In one of many Views, I’ve

@Setting(.openURL) non-public var openURL

var physique: some View {
  VStack {
      Button("Open Browser") {
        openURL(URL(string: "https://some.url")!)
      }
  }
  .navigationTitle("Settings")
}

When clicking the button, the browser launches usually. Nonetheless, when returning to the app utilizing the “again” navigation hyperlink on the highest left, the app first logs

Publishing adjustments from background threads isn't allowed; make sure that to publish values from the principle thread (through operators like obtain(on:)) on mannequin updates.

Then, in a group getter of 1 the Swift Knowledge @Mannequin-s, presupposed to get a group that’s learn when the app’s GUI is rendered, the appliance crashes, saying

Thread 1: Deadly error: Unable to get worth - no backing Managed Object

The entire thing appears to me as if, when switching again from the browser to my app, your complete GUI had been rendered from a non-main thread (which, as this thread additionally has no ModelContainer und ModelContext, can not load the SwiftData fashions).

Sadly, the decision stack of this Deadly Error above isn’t of a lot assist – the generated SwiftData getter is the one Swift code I see there, up the stack are simply areas throughout the compiled meeting code.

P.s. If I simply manually put my app into the background, begin doing one thing else after which return, the app works fantastic.

Why is that this occurring?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments