我觀看了Gerald Versluis關于使用Xamarin.Forms(Android)和FCM的推送通知的教程。視頻教程和源代碼github
我試著下載了源代碼,改變了包的名稱,我只是用我在Firebase云資訊服務上生成的代碼替換了google-services.json代碼。然而,這并不奏效,事件Current_OnTokenRefresh從未觸發,所以我不知道Token。當然,也沒有任何通知。我哪里錯了?
uj5u.com熱心網友回復:
確保你的google-services.json構建動作被設定為GoogleServicesJson,或者你可以簡單地添加"<GoogleServicesJson Include="google-services.json" />"在你的android.csproj檔案內。
uj5u.com熱心網友回復:
步驟1: 確保在你的Android專案的MainAcvtivit.cs中設定reset token = true。 我是這樣做的。
//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true)。
#else
FirebasePushNotificationManager.Initialize(this, false)。
#endif
這個你的OnTokenRefresh應該被觸發了。
CrossFirebasePushNotification.Current.OnTokenRefresh = (s, p) =>
{
Debug.WriteLine($"REC TOKEN : {p.Token}")。
};
步驟2: 檢查你的 "google-services.json "的 "build acion "是否設定為 "GoogleServicesJson"
。步驟3: 檢查您是否為您的應用程式允許這些基本權限。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pusher.pushnotifications" >
<權限 android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<應用
android:fullBackupContent="@xml/backup_rules">
<接收器
android:name="com.pusher.pushnotifications.Reporting.FCMMessageReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<類別 android:name="${applicationId}" />
</intent-filter>
</receiver>
<服務
android:name="com.pusher.pushnotifications.fcm.EmptyMessagingService">
<intent-filter android:priority="1">
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<提供者
android:authorities="${applicationId}.pushnotificationsinitprovider"
android:name="com.pusher.pushnotifications.internal.PushNotificationsInitProvider"
android:exported="false"
android:initOrder="99" />
<活動 android:name="com.pusher.pushnotifications.Reporting.OpenNotificationActivity">
<intent-filter>
<action android:name="com.pusher.pushnotifications.OPEN_TRACKING" />
<類別 android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317277.html
標籤:
