Pooja
Pooja

Reputation: 33

EXC_BAD_ACCESS KERN_INVALID_ADDRESS swiftui

After reading and trying several solutions like enabling zombie,adding exception breakpoint etc didnt worked for me to find the actual reason of my crash. Below is the stack trace for the crash. In my application I am having landing page as biometric validation , if user goes in background and comes back from background again biometric validation will happen. so i have used appstate as environment variable. so when i open the app it shows biometric screen -> success-> dashboard-> background-> network off-> open app -> crash.

if this flow it crashes always where in normal flow it works seamlessly.

    class NetworkMonitor: ObservableObject {
    private let networkMonitor = NWPathMonitor()
    private let workerQueue = DispatchQueue(label: "Monitor")
    var isConnected = false
    var isNotConnected = false
    
    init() {
        networkMonitor.pathUpdateHandler = { path in
            self.isConnected = path.status == .satisfied
            self.isNotConnected = path.status == .unsatisfied
            Task {
                await MainActor.run {
                    self.objectWillChange.send()
                }
            }
        }
        networkMonitor.start(queue: workerQueue)
    }
}

this is the code to check internet connectivity, also in second login option (PIN verification) it works without crash. So I doubt the crash is in biometric class only.

Already invested 2 days in this.looking for your support.

image

enabling zombie,adding exception breakpoint, analysing stack trace of crashlytics

**Please note I also have used environment objects for biometric screen. which are changing based upon app state **

Upvotes: 0

Views: 289

Answers (1)

malhal
malhal

Reputation: 30736

To use async/await in SwiftUI it's .task, e.g. something like this

@State var isConnected = false
@State var isNotConnected = false

...

.task {
    let monitor = NWPathMonitor()
    for await path in monitor {
         isConnected = path.status == .satisfied
         isNotConnected = path.status == .unsatisfied
    }
}

Upvotes: 0

Related Questions