Flurry Integration Using Swift¶
If you prefer to develop iOS apps using Swift and want to integrate Flurry Analytics in your Xcode project, you can accomplish this task with a few simple steps outlined in this guide.
To make this happen, you’ll import a set of Objective-C files in the same app target as your Swift code and use an Objective-C bridging header to expose those files to Swift.
These instructions will only guide you in integrating Flurry Analytics. If you plan on also integrating Flurry Ad Publishing for a Swift project, follow “Option 1” on the iOS Integration Page and import Flurry using Cocoapods.
A screencast of the process illustrates the steps to follow. The entire integration should take no longer than ten minutes.
What You Need¶
For starters, you’ll need to download and install the Flurry SDK on your system.
If you haven’t, follow these links:
Once you download the Flurry SDK and obtain your API keys, you’ll be ready to start a Flurry Session.
Set up is easy and straightforward. Follow these steps:
- Create a Swift-based app from one of the Xcode templates.
- In your Xcode project, select File > Add Files to “demonstration”, navigate to your Flurry SDK and add the following files:
Important: Make sure you’ve checked the Copy Items if needed checkbox under the Destination section.
- In your project, select Build Phases.
- Click the + symbol and add the following frameworks to your project:
Important: Although these frameworks are not required for simple Flurry analytics integration, you’ll need them in order to display ads in your apps.
Configure Bridging Header File¶
Follow these steps:
- Select your demonstration project subfolder.
- Select File > New > File.
You’ll be prompted to choose a template for your new file, which we will select Source under iOS along with Header File.
- When prompted to save the file, name it using the following convention:
projectname-Bridging-Header.h, where projectname is the name of your project (in this case, it’s integration).
- Select your project root and select Build Settings.
- In the search bar, type in Swift Compiler.
- In the “Objective-C Bridging Header” section, double-click the empty space.
You’ll be prompted to enter a path to the bridging header file that you want to expose.
- Enter projectname/projectname-Bridging-Header.h.
- In your “projectname-Bridging-Header.h” file, import Flurry.h:
- Finally, in your AppDelegate.swift file, start typing Flurry.
Now you can import Flurry methods written in Objective-C and use them in our Swift apps. If you need any other files for development, simply import them in projectname-Bridging-Header.h.
Get Started With Flurry Analytics¶
Now that you’ve got your bridging header set up and can import existing Objective-C code, you can begin working with Flurry analytics.
First, let’s create a Flurry Session:
Replace “YOUR_API_KEY” with the API key you received when registering your app through Flurry’s Developer website.
To log events, it’s as simple as this:
where you can replace Started Application with any string of your choice.