how to integrate flurry in ios using swift language

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I want to integrate flurry in ios using swift language. I added the flurry sdk's two files : flurrylib.a and flurry.h and then entered my api key in project TestProject4-Bridging-Header.h

#import "Flurry.h" 

回答1:

I had the same issue and adding a bridging header worked for me. Here are the steps I followed.

Note: If you already have a bridging file, skip the steps 2 to 4

  1. I dragged the Flurry folder to my Swift iOS project in XCode.
  2. I created a bridging header file by creating a new Objective-C header file (in XCode menu it's File/New/File/iOS/Source/Header File)
  3. I called the file name "PROJECTNAME-Bridging-Header.h" (replace PROJECTNAME with your XCode project name)
  4. In Project Build Settings, I searched for "Swift Compile - Code Generation" and there in "Objective-C Bridging Header" I entered the name of my new bridging file (PROJECTNAME-Bridging-Header.h) for debug and release values.
  5. Now, back in my bridging header file, I referenced the Flurry header file.

    #import "Flurry.h"

  6. In my AppDelegate.swift file, I could then call the Flurry methods using Swift:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // setup Flurry Flurry.startSession(flurryKey) // replace flurryKey with your own key Flurry.setCrashReportingEnabled(true) // records app crashing in Flurry Flurry.logEvent("Start Application") // Example of even logging

Hope it helps someone.



回答2:

If you are attempting to log events in the 'didFinishLaunchingWithOptions' using Flurry SDK 6.0.0, this is not possible due to a bug in that version of the SDK. It is possible to start a session from this function however. I was told this information by a Flurry support rep, and confirmed it in my own testing.



回答3:

Flurry Integration using Pods in Swift

You need to import Flurry SDK as Follows

import Flurry_iOS_SDK   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {          Flurry.startSession("YOUR_API_KEY")          Flurry.logEvent("Started Application")     } 


回答4:

You need to add a bridging header to your project. In that bridging header you import what you need in Swift and then you don't need to import it anywhere else. The iBook on using Swift and Obj-C alongside has a very good explanation on this.

Actually, there is an explanation on Apple's Swift blog that says:

To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.

You can find more information here.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!