docchang
docchang

Reputation: 1125

FirebaseException: The operation couldn't be completed. No APNs token specified before fetching FCM Token

I'm not sure what else I need to do to get the FCM Token. Perhaps I'm missing a step. Below are the details of my current setup.

This is an Unity iOS build calling GetTokenAsync.

Firebase.Messaging.FirebaseMessaging.GetTokenAsync();

However, I'm getting an exception.

FirebaseException: The operation couldn’t be completed. No APNS token specified before fetching FCM Token

I've generated an APN Key for push notification and uploaded to Firebase, but I'm not sure do I need to included it somehow with Xcode?

I've enabled Background Modes. enter image description here

Upvotes: 2

Views: 17284

Answers (4)

Fangh
Fangh

Reputation: 75

I changed

async void InitializeFirebase()
{
    FirebaseMessaging.MessageReceived += OnMessageReceived;
    FirebaseMessaging.TokenReceived += OnTokenReceived;
}

to

async void InitializeFirebase()
{
    FirebaseMessaging.MessageReceived += OnMessageReceived;
    await RegenerateFcmToken();
}
private async Task RegenerateFcmToken()
{
    try
    {
        Log("Requesting new FCM Registration Token ...");
        await FirebaseMessaging.DeleteTokenAsync();
        await FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread(task =>
        {
            if (task.Exception != null)
            {
                Log(task.Exception.Message);
                return;
            }

            fcmToken = task.Result;
            Log("Received Registration Token: " + fcmToken);

        });

    }
    catch (Exception e)
    {
        Log(e.Message);
        throw;
    }
}

And I don't have the message "No APNS token specified before fetching FCM Token" anymore

Upvotes: 0

sylvin rodrigues
sylvin rodrigues

Reputation: 1

use following pod version it will work

pod 'Firebase/Messaging', '10.6.0'

add following properties in info.plist

<key>FirebaseAppDelegateProxyEnabled</key>
    <false/>

Upvotes: 0

Mohammad Soltani
Mohammad Soltani

Reputation: 73

You should use last version of firebase_message and firebase_core.

firebase_core: ^2.17.0
firebase_messaging: ^14.6.9

this will work fine.

Upvotes: -1

Joe Spiro
Joe Spiro

Reputation: 347

There are multiple reasons this could be happening. The following instruction steps are included in the Set up FCM for Unity Guide.

Try each of the following (if you haven't already):

  • Enable Push Notifications in Xcode under App > Capabilities
  • Add UserNotifications.framework in Linked Frameworks and Libraries
  • Switch Push Notifications to On in capabilities
  • Make sure method swizzling is enabled

If this doesn't work then look through the logs before and after the message you are getting above and see if there are earlier messages relating to warnings or failures with FCM or APNS.

Please tell me how it works out for you.

Upvotes: 2

Related Questions