Lifecycle & status
Bugsee works in the background of your app. When you need to know what it is doing — whether it is recording yet, or when a report is shown or uploaded — use the SDK status and the lifecycle events described here. Stopping and relaunching are covered in Configuration.
Setting the delegate
Status changes and lifecycle events are delivered to your BugseeDelegate. Every delegate method is optional: implement the ones you need, and set your object as the delegate. Bugsee holds the delegate weakly, so keep a strong reference to it yourself.
In Swift, derive the delegate from NSObject, so you do not have to implement the NSObjectProtocol requirements yourself.
- Objective-C
- Swift
@interface MyBugseeDelegate : NSObject <BugseeDelegate>
@end
// ...
[Bugsee sharedInstance].delegate = self.bugseeDelegate;
final class MyBugseeDelegate: NSObject, BugseeDelegate {
// ...
}
// ...
Bugsee.sharedInstance()?.delegate = bugseeDelegate
You can set the delegate before launchWithToken:.
SDK status
launchWithToken: returns before Bugsee is recording. status tells you where the SDK is:
| Value | Meaning |
|---|---|
BugseeStatusStopped | Not launched, a launch that waits for the app to become active, or fully stopped. Calls that submit data are ignored. |
BugseeStatusLaunching | The SDK is starting capture. Reports can be filed, but logs, events, traces, breadcrumbs and network events may not be recorded yet. |
BugseeStatusLaunched | Fully running: capture is recording. |
BugseeStatusStopping | stop: is in progress. |
The launched property is YES only while the status is Launched. Prefer status, or the status callback below, for launch sequencing.
When the launch waits for the app to become active
When launchWithToken: is called while the app is in the background state, or before UIApplication exists, Bugsee installs its crash handler right away and starts everything else when the app becomes active. That is the case for a launch from application:didFinishLaunchingWithOptions: in a scene-based app, and for a launch from a SwiftUI App initializer. Until the app becomes active:
- the status stays
Stopped, and the first transition is toLaunchingat that moment; - calls that submit data (
log,event,trace,logError:,logException,upload…,notify) are ignored; startTransactionandstartSpanreturn objects that record nothing;BugseeOptionCaptureNetworkOnLaunchhas no effect, so requests started in that window are not captured.
Once the status is Launched, all of these work as usual.
- Objective-C
- Swift
if ([Bugsee sharedInstance].status == BugseeStatusLaunched) {
// Bugsee is recording
}
if Bugsee.sharedInstance()?.status == BugseeStatusLaunched {
// Bugsee is recording
}
Observing status changes
bugseeDidChangeStatus: (Swift bugsee(didChangeStatus:)) is called on the main thread on every status transition, including the Launching and Stopping steps that no lifecycle event covers.
- Objective-C
- Swift
- (void)bugseeDidChangeStatus:(BugseeStatus)status {
if (status == BugseeStatusLaunched) {
// Bugsee is recording
}
}
func bugsee(didChangeStatus status: BugseeStatus) {
if status == BugseeStatusLaunched {
// Bugsee is recording
}
}
The launch completion
launchWithToken:options:started: (Swift launch(token:options:started:)) calls its block once:
- For a launch that starts right away, it is called once capture is up, with
YES, or withNOif the launch failed or astop:cancelled it. - For a launch that waits for the app to become active, it is called at once with
YES: the launch was accepted, but recording has not begun. NOalso means the launch was refused, for example because the app token is empty or the SDK is stopping.- A launch called while Bugsee is already running reports
YES, and its options are ignored.
To know when recording has begun, observe the status.
- Objective-C
- Swift
[Bugsee launchWithToken:@"<your_app_token>"
options:nil
started:^(BOOL success) {
NSLog(@"Bugsee launch accepted: %d", success);
}];
Bugsee.launch(token: "<your_app_token>", options: nil) { success in
print("Bugsee launch accepted: \(success)")
}
Lifecycle events
Lifecycle events report discrete moments: a launch, a report shown or uploaded, a blackout started. Implement bugseeLifecycleEvent: (Swift bugsee(lifecycleEvent:)) to receive them. They are delivered on the main queue.
- Objective-C
- Swift
- (void)bugseeLifecycleEvent:(BugseeLifecycleEventType)eventType {
if (eventType == BugseeLifecycleEventRelaunchedAfterCrash) {
// The previous run crashed
}
}
func bugsee(lifecycleEvent eventType: BugseeLifecycleEventType) {
if eventType == BugseeLifecycleEventRelaunchedAfterCrash {
// The previous run crashed
}
}
Lifecycle events and status changes are delivered separately and are not ordered against each other: with a cross-platform SDK in the app, a lifecycle event can arrive after a later status change.
Available lifecycle events
| Event | Dispatched when |
|---|---|
BugseeLifecycleEventLaunched | Bugsee was launched. |
BugseeLifecycleEventStopped | Bugsee was stopped. |
BugseeLifecycleEventRelaunchedAfterCrash | Bugsee was launched and found a crash left by its crash handler in an earlier run. Dispatched at most once per process. Exit reports, including the watchdog and memory-limit reports of the Crash Report Extension, do not dispatch it. |
BugseeLifecycleEventBeforeReportShown | Before the report dialog is shown. |
BugseeLifecycleEventAfterReportShown | After the report dialog is shown. |
BugseeLifecycleEventBeforeReportAssembled | Before a bug, crash or error report starts being assembled. |
BugseeLifecycleEventAfterReportAssembled | After a report has been assembled. |
BugseeLifecycleEventReportAssemblyFailed | Assembling a report ran out of attempts in this process. Assembly that is interrupted instead, because the process ends or Bugsee is stopped, resumes on a later launch and does not dispatch this event. |
BugseeLifecycleEventBeforeReportUploaded | A report is about to be uploaded. |
BugseeLifecycleEventAfterReportUploaded | A report was uploaded. |
BugseeLifecycleEventReportUploadFailedWithFutureRetry | A report upload failed and will be retried later. |
BugseeLifecycleEventReportUploadFailed | Repeated upload attempts failed. No more attempts are made, and the report is not uploaded. |
BugseeLifecycleEventBlackoutStarted | A blackout began (startBlackout). A relaunch that keeps a blackout dispatches BlackoutEnded and then BlackoutStarted. |
BugseeLifecycleEventBlackoutEnded | A blackout ended (endBlackout, or stop:). |
BugseeLifecycleEventBeforeFeedbackShown | Reserved for the feedback screen; not dispatched yet. |
BugseeLifecycleEventAfterFeedbackShown | Reserved for the feedback screen; not dispatched yet. |
7.x has no pause and resume, so the 6.x BugseeLifecycleEventStarted, BugseeLifecycleEventPaused and BugseeLifecycleEventResumed events are gone, and the raw values of the remaining events changed. Compare against the constants, never against numbers. See Migrating from 6.x to 7.x.