Created
October 8, 2017 14:32
-
-
Save wuhuangjia/70b8bf852c3f1fea437a15afe3ae0fd9 to your computer and use it in GitHub Desktop.
Medium 文章:Xamarin + Prism + Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Android.App; | |
using Android.Content; | |
using Android.OS; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Widget; | |
using XFFirebase.Droid.Service; | |
using XFFirebase.Interface; | |
using Firebase.Analytics; | |
using Xamarin.Forms; | |
//Xamarin 相依性注入的語法 | |
[assembly: Xamarin.Forms.Dependency(typeof(FireBaseAnalyticsService))] | |
namespace XFFirebase.Droid.Service | |
{ | |
//繼承 PCL 專案中的介面,並依照原生平台的寫法實作 | |
class FireBaseAnalyticsService : IFireBaseAnalyticsService | |
{ | |
private FirebaseAnalytics _firebaseAnalytics; | |
public FirebaseAnalytics firebaseAnalytics | |
{ | |
get | |
{ | |
if (_firebaseAnalytics == null) | |
{ | |
firebaseAnalytics = FirebaseAnalytics.GetInstance(Forms.Context); ; | |
} | |
return _firebaseAnalytics; | |
} | |
set { _firebaseAnalytics = value; } | |
} | |
public FireBaseAnalyticsService() { } | |
public void LogEvent(string name, Dictionary<string, object> boundle) | |
{ | |
//將由 PCL 專案傳過來的參數重新用 Android 版 Firebase 所需要的格式填回去 | |
var p = new Bundle(); | |
foreach (var item in boundle) | |
{ | |
p.PutString(item.Key, Convert.ToString(item.Value)); | |
} | |
firebaseAnalytics.LogEvent(name, p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment