Swift + SwiftUI

If your application is written in Swift and uses SwiftUI as the entry point to the UI, follow these steps: ​

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

  2. Add the import PulseLabsFlightRecorderSDK statement to the top of the file:

    import SwiftUI
    
    // Insert the import statement:
    import PulseLabsFlightRecorderSDK
    
    @main
    struct MyApp: App {    
  3. Observe the scenePhase value in the Environment, if you are not already doing so, using @Environment(\.scenePhase) private var scenePhase indicated in the example below at (A). Then, check when the phase is .active using .onChange(of: scenePhase) and if phase == .active, as shown in the below example at (B) and (C). Finally, insert the FlightRecorderSDK.start(apiKey: "YOUR_API_KEY") line of code so that it runs whenever the ScenePhase becomes .active as shown below at (D), replacing "YOUR_API_KEY" with your own API key. There are also 2 other parameters that are optionals: - surveyName: if you have designed an in-app survey on the portal, then supply the unique survey name string here, and it will show that instead of the default form - customFontsLib: you can also create an instance of FlightRecorderCustomFontsLib as pass it here. The sdk then will use that font to decorate the in-app survey form with it

    import SwiftUI
    import PulseLabsFlightRecorderSDK
    
    @main
    struct MyApp: App {
    
        // A: Observe the scenePhase value in the Environment
        @Environment(\.scenePhase) private var scenePhase
    
        var body: some Scene {
            WindowGroup {
                MyRootView()
            }
            
            // B: add thhe .onChange
            .onChange(of: scenePhase) { phase in
                
                // C: Insert the check for phase .active
                if phase == .active {
                    
                    // D: Insert the SDK start function call, replacing YOUR_API_KEY with your API key
                    FlightRecorderSDK.start(
                        apiKey: "YOUR_API_KEY",
                        surveyName: "SURVEY_NAME"?,
                        customFontsLib: FlightRecorderCustomFontsLib?
                    )
                }
            }
        }
    }

The SDK is now installed! Run your app on a real device (the SDK will not work in a simulator) and the introduction screen will appear on the first run. You can then shake or take a screenshot to capture the video content and send a report.

If you have any issues, head to the Troubleshooting section.

Last updated