Reputation: 147
I added to my project Firebase Cloud Messaging for receiving and sending push notifications. I followed steps in original tutorial from Google. The result was exciting, I can receive push notification on my device - I published it to TestFlight - problem occurred.
I realize that I need to create different certificate. (???) Then I delete my key (.p8) from Firebase Cloud messaging and recreated it (development too) + I recreated same development provisioning profile (old ones I revoke), I repeated process from tutorial but now I can't get push notification even in my device, neither on TestFlight.
Can anyone help me with these questions?
Please help me from this. Thanks!
[UPDATE][SOLVED] After completing the steps from this answer and changing the Team ID in Firebase to same Team ID from Apple Developer I was able to receive notification to my device and all the TestFlight devices.
Upvotes: 5
Views: 24939
Reputation: 11
Steps I Followed and which worked like a Charm were :
Setup your Firebase:
Setup Unity:
Add your TeamID from appstore connect to the field available under project setting of your Unity project
also check true auto init next to teamID field in project setting
use this code to init Firebase
private void Start()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
{
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
Debug.Log("Firebase Init");
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}
else
{
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
}
});
}
#region FIREBASE MESSAGING
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
UnityEngine.Debug.Log("Received Registration Token: " + token.Token);
}
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{
UnityEngine.Debug.Log("Received a new message from: " + e.Message.From);
}
#endregion
Make build after this
Setup Xcode :
Upvotes: 1
Reputation: 2707
Make sure you don't rename the auth key file
In my case, I had renamed the auth key file to something else and that was causing the issue. I tried naming it back to the default format AuthKey_<KeyID>.p8
and everything started working.
Upvotes: 1
Reputation: 715
In my case it was the wrong APNs Authentication Key we have uploaded the wrong file to firebase console, once replaced with the correct APN key, the notifications worked like a charm. No changes to the code needed
Upvotes: 1
Reputation: 483
In our case it was that in the main project settings the team id was set to the team name, after changing that and uploading the APN key again with the right team id it started working, so you might want to double check that.
Upvotes: 1
Reputation: 413
Firebase has nothing to do with the development and production. It would be on your end if you are using two different firebase apps, one for the development and other for the production.If that is the case you just have change the GoogleService-Info.plist for the respective environments. Here are my steps you should follow to properly implement Firesbase Push Notifications.
1) Go to your apple developer account and create a new key for APNS. (Reference)
2) Create a firebase project and add an iOS app, then in Cloud Messaging tab in the your App settings add the Key you just created in the 1st step with KeyID and TeamID.
3) Add the GoogleService-Info.plist to the root of your project and add the Push Notification from the capabilities in Xcode.
4) Then initialize the firebase in your app (Reference)
5) Add the code to ask for Notification permissions on app startup.
6) And finally get the fcmToken from this method
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
And send a notification to that token from firesbase.
Note: For provisioning profiles, enable the automatic signing in Xcode and Xcode will do the signing process itself. Now we don't need create the provisioning profiles manaually.
Upvotes: 10