Initialization

Initialization

You initialize Embrace.io by calling startWithKey: from within your AppDelegate, passing in your provided API key. We strongly recommend that you place the Embrace initialization call on the first line of your **application:didFinishLaunchingWithOptions callback**. This ensures the most accurate reporting time for your application’s startup process, and allows Embrace to begin instantly monitoring other SDKs that your app initializes throughout the rest of its lifecycle.

Please instantiate the Embrace SDK synchronously, i.e. not on a dispatch_async block. Embrace does most of its processing on async queues, but instantiating synchronously helps us best catch any issues during your app’s startup.

Initializing the Embrace.io SDK is also what triggers the beginning of the startup event.

Objective-C

in AppDelegate.m

#import <Embrace/Embrace.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[Embrace sharedInstance] startWithKey:<YOUR-API-KEY>];

    ...

    return YES;
}

Swift

in AppDelegate.swift

import Embrace

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Embrace.sharedInstance().start(withKey: <YOUR-API-KEY>)

    ...

    return true
}

Ending App Startup

The Embrace.io SDK automatically begins recording the startup event once it’s intialized, so the next step is to inform the SDK that app startup is complete. Where you put this call is entirely dependent on the structure of your app — common use cases are once a user’s home feed is loaded, a sign-in screen is displayed, or more generally the instant before the first screen becomes interactive.

If you have more than one location in your app where startup could end, such as in a push notification handler or various screens for logged in/logged out users, it’s okay to add multiple **endAppStartup calls**. This ensures that you don’t see erroneous failed startups on your dashboard in the event that a code path is followed where the startup is not ended.

Objective-C

E.g. in SomeViewController.m

#import <Embrace/Embrace.h>

- (void)viewDidLoad
{
    ...

    [[Embrace sharedInstance] endAppStartup];
}

Swift

E.g. in SomeViewController.swift

import Embrace

override func viewDidLoad() {
    ...

    Embrace.sharedInstance().endAppStartup()
}

Boom. Your app is now sending data for the startup event, as well as monitoring for CPU, memory, and networking issues over the course of the user’s session.