Integrate Flurry SDK for tvOS

Integrating the Flurry tvOS SDK for tvOS apps with is easy and straightforward. Support is provided for both native and client-server apps.

Using Flurry Analytics for tvOS, you can measure app performance with standard Flurry Analytics metrics, as well as Sessions and Active Devices metrics in real time.

Prerequisites: Xcode 7 and above.

Follow these instructions to get started.

Create an App & Get Your API Keys

Start by creating a new tvOS app. Once you create the app, you’ll receive a Flurry API Key, which you’ll need for SDK instrumentation.

Sign up  or  Create an App for tvOS

Note

For each distinct tvOS app that you create, you’ll need to acquire a unique Flurry API Key.

Import Flurry Libraries

Follow these basic integration steps for native and client-server apps:

  1. Download the SDK for your tvOS project. The downloaded SDK includes the required library containing Flurry’s collection and reporting code.
  2. Add the SDK files.
  3. Open your Xcode project and click your project’s subfolder, as shown in the screen illustration below.

tvos tvtest
  1. Click File > Add Files to your-build-target-name. In this window, navigate to the downloaded Flurry SDK and add the folder FlurrytvOS.
  2. Once you’ve added these folders, open the options tab at the lower left corner and do the following:
  • Check Copy items if needed to move the files to the project, not just reference them.
  • Select Create groups to organize the Flurry folders only visually in Xcode and prevent any errors from hierarchical organization.
  • Check your-build-target-name under Add to targets to ensure the libraries are linked to the binary.
  1. Once you check the Linked Libraries, click on your project, then select Build Phases and look under Link Binary with Libraries, as shown in the screen illustration below. Make sure the tvOS library you are using is listed here.

tvos test
  1. Depending on the Flurry libraries you are using, add the following framework to your build target by clicking the “+” button:
  • SystemConfiguration.framework

Swift SDK Integration

For Swift integration, you’ll need to implement a Bridging Header. Follow these steps if you are importing manually using Swift.

  1. Create the Bridging Header:
  • Click on your project’s subfolder (the folder with your app delegate, storyboard, and view controller under it).
  • Click File > New > File. You’ll be prompted to choose a template for your new file, which you will select Source under iOS along with Header File.
  1. Save the Bridging Header:
  • When prompted to save the file, name it using the following convention: projectname-Bridging-Header.h, where projectname is the name of your project.
  1. Expose the Bridging Header:
  • Select your project root and select Build Settings.
  • Make sure All not Basic is highlighted and then navigate to the Swift Compiler section.
  • Add the path to your Bridging Header as a key to the Objective-C Bridging Header item: projectname/projectname-Bridging-Header.h.

tvos bridging header
  1. Import Objective-C libraries using the Bridging Header.
  • Select the Bridging Header file you created and add the import statement #import Flurry.h.

The following bridging header example integrates Flurry Analytics for tvOS.

#ifndef tvTest_Bridging_Header_h
#define tvTest_Bridging_Header_h

#import "Flurry.h"

#endif /* tvTest_Bridging_Header_h */

Initialize Flurry

To finish integrating Flurry, you’ll need to import Flurry in your Application Delegate and start a Flurry session inside applicationDidFinishLaunching, as described for Objective-C and Swift.

For Objective-C:

#import "Flurry.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Replace YOUR_API_KEY with the api key in the downloaded package
[Flurry startSession:@"YOUR_API_KEY"];
}

For Swift:

import "Flurry_iOS_SDK" //this is only needed if the libraries were obtained using CocoaPods
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Replace YOUR_API_KEY with the api key in the downloaded package
Flurry.startSession("YOUR_API_KEY")
return true
}

Additionally for client-server apps

Note that this step is only necessary if you app is a client-server app.

Client-server apps require the Application Delegate to conform to TVApplicationControllerDelegate.

Inside theappController:evaluageAppJavaScriptInContext of TVApplicationControllerDelegate you need to register theJSContext with the FlurryTVOS SDK, shown as follows for Objective-C or Swift:

For Objective-C:

(void)appController:(TVApplicationController *)appController evaluateAppJavaScriptInContext:(JSContext *)jsContext {
  [Flurry registerJSContextWithContext:jsContext];
}

For Swift:

func appController(appController: TVApplicationController, evaluateAppJavaScriptInContext jsContext: JSContext) {
Flurry.registerJSContextWithContext(jsContext)

}

This additional step for client-server apps makes JavaScript methods globally available to the JavaScript domain.

Now test run your tvOS app and ensure that it builds without errors. If everything is working properly, a session will be recorded in Flurry and should be visible on your Real Time dashboard within 30 seconds.

Important

If you created the Flurry app within the last 5 minutes, the app may not yet be live on our servers and thus will not reflect real-time data. Re-run your app after 5 minutes to see your session recorded on the Real Time dashboard.

Congratulations! Your tvOS app is now ready to be used with Flurry Analytics.

Moving On To Custom Events

Now that you’ve completed the basic SDK integration setup, you’re ready to move on to custom events, which enable you to better understand user behavior through Custom Events.

Need Help?

Check out our robust collection of FAQs and a detailed Lexicon of key terminology. Didn’t find what you were looking for. Our team is answering questions on Flurry Forums.

Have Feedback?

We’d love to hear your suggestions for us. Please visit our Feedback Board to submit your ideas.