Files
2024-08-04 14:29:43 -04:00

2.6 KiB

PulseUI

A set of components that you can integrate into your app to view the logs.

Overview

The easiest way to integrate PulseUI is by using ConsoleView.

// Present modally
Text("Console").sheet(isPresented: $isConsolePresented) {
    NavigationView {
        ConsoleView()
    }
}
// Push into the navigation stack.
NavigationLink(destination: ConsoleView()) {
    Text("Console")
}

tip: If you use Pulse to log only network requests, and not text messages, use ConsoleView(mode: .network) to show a view specialized to only display network requests.

UIKit

To present the console from UIKit, use UIHostingController:

let view = NavigationView { 
    ConsoleView()
}
present(UIHostingController(rootView: view), animated: true)

If you are using appearance to change the navigation bar isTranslucent property to false, make sure to set extendedLayoutIncludesOpaqueBars to true:

let vc = UIHostingController(rootView: ConsoleView())
vc.extendedLayoutIncludesOpaqueBars = true
let nav = UINavigationController(rootViewController: vc)
nav.navigationBar.prefersLargeTitles = true
present(nav, animated: true)

Custom Views

PulseUI gives you complete access to the underlying data and its model. You can easily create custom views into your log data by using affordances provided by SwiftUI:

struct AnalyticsLogsView: View {
    @FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \LoggerMessageEntity.createdAt, ascending: true)],
        predicate: NSPredicate(format: "label == %@", "analytics")
    ) var messages: FetchedResults<LoggerMessageEntity>
    
    var body: some View {
        List(messages, id: \.objectID) { message in
            NavigationLink {
                Text("TODO: your details view here")
            } label: {
                VStack(alignment: .leading) {
                    HStack {
                        Text(timeFormatter.string(from: message.createdAt))
                            .font(.footnote)
                            .foregroundColor(.secondary)
                        Spacer()
                        ListDisclosureIndicator()
                    }
                    Text(message.text)
                        .lineLimit(2)
                }
            }
        }
        .listStyle(.plain)
    }
}

private let timeFormatter = DateFormatter(format: "HH:mm:ss.SSS")

tip: For a complete example, see the Integrations demo.

PulseUI on watchOS

Topics

Main Views

  • ConsoleView
  • SettingsView
  • UserSettings

Deprecated

  • MainViewController