2016-08-21 57 views
2

我想在我的自定义键盘中为按钮点击事件实施Firebase谷歌分析。如何在自定义键盘中实施Firebase Google Analytics?

任何人都请告诉我如何在swift中做到这一点。

+0

我投票关闭这一问题作为题外话,因为这是正常的,因为使用谷歌Analytics(分析)。 没有什么特别的键盘。 –

+1

@Zaid Pathan,正常实现有很大的麻烦,例如崩溃[原因:'默认应用程序已被配置。]。所以我问了这个问题。如果您知道解决方案,请帮助我,因为我在radugrinico的回答下描述了我的问题。 –

+0

你可以尝试两次调用'FIRApp.configure()'两次,你打电话吗? 它可能会解决这个问题。这里是类似的东西:http://stackoverflow.com/questions/37910766/app-crashing-when-using-firebase-auth-reason-default-app-has-already-been-con –

回答

3

将firebase sdk和GoogleService-Info.plist文件添加到键盘扩展目标。导入Firebase并进行配置。 FIRApp.configure()必须调用每会话一次:

import Firebase 

class FirebaseConfigurator: NSObject { 
static var onceToken: dispatch_once_t = 0 

static func configure() { 
    dispatch_once(&onceToken) { 
     FIRApp.configure() 
    } 
} 

FirebaseConfigurator.configure() 
FIRAnalytics.logEventWithName("button click event", parameters: nil). 
+0

我做了同样的事情,但问题是当我将自定义键盘切换到原生iOS键盘,并再次原生自定义时,再次调用'FIRApp.configure()'方法并抛出**错误 - [原因:'默认应用程序已被配置。] **和应用崩溃。 –

+0

@SunilTarge,您需要确保每个会话只调用一次FIRApp.configure()。 – radugrinico

+0

是的,我明白,但我不知道如何计算新的扩展键盘会话。因为它没有AppDelegate类。 –

相关问题