2016-08-21 53 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類。 –

相關問題