Xcode iOS 14 WidgetKit not always attached to debugger

Viewed 835

I'm developing WidgetKit extension on iOS 14, however, the extension doesn't always connect to Xcode debugger after build and run, causing I can't see logs, as this image shows: (But sometimes it'll automatically attach, I don't know why)

enter image description here

If the extension is attached to debugger, it should look like this, and print logs:

enter image description here

Manually attach process to debugger doesn't works, it should be attached at first launch to see logs.

Does anyone know how to properly debug iOS 14 widget?

3 Answers

Try plugging in your physical device and running it on that instead of a simulator. That fixed the logging issue for me.

To debug, or see print info: (This works for me)

On the top left of Xcode->
Click project name, you can see a list, select widget name, run it
Click widget name, you can see a list, select project name, run it
Xcode: Version 12.3, iPad: iPadOS 14.3

You can log your useful information in local file, just like this:

public func XXLogToFile(_ text: String) {
    if let documentsDirectory = FileManager().containerURL(forSecurityApplicationGroupIdentifier: "group.xxx") {
        let logFileUrl = documentsDirectory.appendingPathComponent("log.txt")
    
         do {
            var logContent = try String(contentsOf: logFileUrl, encoding: .utf8)
            logContent = (logContent.count > 0 ? "\(logContent)\n\(text)" : text)
            try logContent.write(to: logFileUrl, atomically: false, encoding: .utf8)
        }
        catch {}
    }
}
Related