2017-08-07 65 views
2

單個iOS應用構建可以同時向兩個Firebase項目報告嗎?我想從同一個版本同時向我自己的個人Firebase帳戶和我的客戶的Firebase帳戶發送活動。同時向兩個Firebase項目報告

我調查過使用Google跟蹤代碼管理器解決此問題,但沒有成功。

回答

1

應該有可能。

查看Firebase博客中的this post。同樣的原則適用於所有平臺,但iOS特定的東西在底部。

通過它的外觀,這就是你所需要的最短(IOS)的示例代碼:

// Alt: load from plist using |FIROptions(contentsOfFile:)| 
let options = FIROptions(googleAppID: googleAppID, bundleID: bundleID, GCMSenderID: GCMSenderID, APIKey: nil, clientID: nil, trackingID: nil, androidClientID: nil, databaseURL: databaseURL, storageBucket: nil, deepLinkURLScheme: nil) 

FIRApp.configure(withName: "secondary", options: fileopts) 
guard let secondary = FIRApp.init(named: "secondary") 
     else { assert(false, "Could not retrieve secondary app") } 

let secondaryDatabase = FIRDatabase.database(app: secondary); 
1

如果你想火力地堡應用程式分別初始化爲多個項目。 您需要先創建一個Firebase選項對象來保存Firebase應用程序的配置數據。對於選項的完整文檔可以爲以下類的API參考文檔中找到:

的iOS:FirebaseOptions init

// Configure with manual options. 
let secondaryOptions = FirebaseOptions.init(googleAppID: "1:27992087142:ios:2a4732a34787067a", gcmSenderID: "27992087142") 
secondaryOptions.bundleID = "com.google.firebase.devrel.FiroptionConfiguration" 
secondaryOptions.apiKey = "AIzaSyBicqfAZPvMgC7NZkjayUEsrepxuXzZDsk" 
secondaryOptions.clientID = "27992087142-ola6qe637ulk8780vl8mo5vogegkm23n.apps.googleusercontent.com" 
secondaryOptions.databaseURL = "https://myproject.firebaseio.com" 
secondaryOptions.storageBucket = "myproject.appspot.com" 

更多細節here