Show the Introduction Screen

The SDK displays the introduction screen during the very first app launch, considering this the trigger. This feature enables you to add extra triggers and also allows you to disable the default app launch trigger.

For instance, you may choose to present the introduction screen at the end of your onboarding screens or provide an option to show it again from a help menu.

Select a Trigger and Show the Introduction Screen

Select a Trigger

Decide from where you want to show the introduction screen. For example, at the end of your onboarding screens or when a button in a menu is pressed. We will call this the trigger. This simple example shows a possible trigger - when a button is pressed in a SwiftUI app.

Swift
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")

            Button(action: {
                self.buttonPressed()
            }) {
                Text("Press Me")
                    .padding()
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
    }


    private func buttonPressed() {
        // This will be the trigger        
    }
}

Show the Introduction Screen from the Trigger

Place an import statement to import the SDK at the top of the file containing the trigger (the event which will trigger the display of the introduction screen). For example, this might be a View Controller, or a View.

Swift
import PulseLabsFlightRecorderSDK
Objective-C
#import <PulseLabsFlightRecorderSDK/PulseLabsFlightRecorderSDK-Swift.h>

Call showIntroductionUI (Swift), or showIntroductionUIWithDisplayOnlyOnce:error: (Objective-C), at the moment you want to show the introduction screen inside the trigger, handling any errors thrown:

Swift
do {
    try FlightRecorderSDK.showIntroductionUI(displayOnlyOnce: false)
} catch {
    // Handle the error if you wish (see note below)
}
Objective-C
NSError *error = nil;
[FlightRecorderSDK showIntroductionUIWithDisplayOnlyOnce:false error:&error];
if (error) {
    NSLog(@"Error: %s", "FlightRecorderSDK not yet started, cannot show introduction screen.");
}

The above examples will display the introduction screen each time the function containing the showIntroductionUI: or showIntroductionUIWithDisplayOnlyOnce:error method is called. If you only want to show the introduction screen the first time the function is called, set displayOnlyOnce to true.

The only error the SDK throws is the FlightRecorderSDKError.failedToStart error. To effectively handle this error, consider logging it directly to the console, or alternatively, utilize your preferred logging framework.

If you do encounter the FlightRecorderSDKError.failedToStart error, it indicates that the triggerCaptureRecording function was called before initializing the FlightRecorderSDK with the start function.

To resolve this issue, ensure that you call FlightRecorderSDK.start during your application's initialization phase as shown in the SDK Configuration section, before invoking any further functions.

Here is the completed SwiftUI example, completed by calling the method from the onButtonClick function:

Swift
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")

            Button(action: {
                self.buttonPressed()
            }) {
                Text("Press Me")
                    .padding()
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
    }


    private func buttonPressed() {
        // This will be the trigger
        do {
            try FlightRecorderSDK.showIntroductionUI(displayOnlyOnce: false)
        } catch {
            // Handle the error if you wish (see note below)
        }        
    }
}

Prevent the Introduction Screen from Showing on First Launch

If you do not wish to show the introduction screen when you first launch the app, follow the instructions for your language and framework.

SwiftUI

  1. Navigate to the main entry point of your application, which is annotated with @main and contains your App instance. ​

  2. Locate the code that starts the SDK by searching for FlightRecorderSDK.start.

  3. Set automaticallyShowIntroduction: false when starting the SDK as shown:

    Swift
    FlightRecorderSDK.start(apiKey: "YOUR_API_KEY", automaticallyShowIntroduction: false) 

  4. Save your changes. The introduction UI will no longer show on first launch.

UIKit with Scenes

  1. Navigate to the SceneDelegate file within your project.

  2. Locate the code that starts the SDK by searching for FlightRecorderSDK.start.

  3. Set automaticallyShowIntroduction: false when starting the SDK as shown:

    Swift
    FlightRecorderSDK.start(apiKey: "YOUR_API_KEY", automaticallyShowIntroduction: false) 

    Objective-C
    [FlightRecorderSDK startWithApiKey:@"YOUR_API_KEY" automaticallyShowIntroduction:FALSE]; 
  4. Save your changes. The introduction UI will no longer show on first launch.

UIKit without Scenes

  1. Navigate to the AppDelegate file within your project.

  2. In the applicationDidBecomeActive(_:) method, locate and delete the following lines depending on the language you are using:

    Swift
    showIntroductionUI(displayOnlyOnce: true)

    Objective-C
    NSError *error = nil;
    [FlightRecorderSDK showIntroductionUIWithDisplayOnlyOnce:true error:&error];
    if (error) {
        NSLog(@"Error: %s", "FlightRecorderSDK not yet started, cannot show introduction screen.");
    }
  3. Save your changes. The introduction UI will no longer show on first launch.

Last updated