ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
516 stars 581 forks source link

iOS Push Notifications can't get FCM token #652

Closed RidClick closed 2 years ago

RidClick commented 2 years ago

Bug Report

Plugin(s)

"@capacitor/push-notifications": "^1.0.4",

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 3.2.4
  @capacitor/core: 3.2.4
  @capacitor/android: 3.2.4
  @capacitor/ios: 3.2.4

Installed Dependencies:

  @capacitor/cli: 3.2.4
  @capacitor/android: 3.2.4
  @capacitor/core: 3.2.4
  @capacitor/ios: 3.2.4

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

iOS

Current Behavior

I have tried installing the PushNotifications plugin as the capacitor guide says. I have followed the guide step by step without any problem. But I have not managed to make it work correctly and I think they are due to the way of obtaining the FCM Token. I have up to date the iOS APNS and the Firebase project linked correctly since in Android it does not give me any problem. However with iOS it seems that it does not finish connecting with Firebase or the guide is missing a component to implement..

In any case I attach the errors that I think are responsible for this problem. (I have replaced with "x" what I think is sensitive data)

2021-10-08 17:53:55.303503+0200 App[1217:592394] 8.8.0 - [Firebase/Messaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID 'xxxxxxxx'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.

2021-10-08 17:53:55.953755+0200 App[1217:592412] 8.8.0 - [Firebase/Installations][I-FIS001003] Request response received: <NSMutableURLRequest: 0x282204360> { URL: https://firebaseinstallations.googleapis.com/v1/projects/centrix-xxxx/installations/ }, error: (null), body: {
  "error": {
    "code": 403,
    "message": "Requests to this API firebaseinstallations.googleapis.com method google.firebase.installations.v1.FirebaseInstallationsService.CreateInstallation are blocked.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_SERVICE_BLOCKED",
        "domain": "googleapis.com",
        "metadata": {
          "service": "firebaseinstallations.googleapis.com",
          "consumer": "projects/xxxxxx"
        }
      }
    ]
  }
}
.
2021-10-08 17:53:55.955136+0200 App[1217:592412] 8.8.0 - [Firebase/Installations][I-FIS001004] Unexpected API response: <NSHTTPURLResponse: 0x2827074a0> { URL: https://firebaseinstallations.googleapis.com/v1/projects/centrix-xxxx/installations/ } { Status Code: 403, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
    );
    "Cache-Control" =     (
        private
    );
    "Content-Encoding" =     (
        gzip
    );
    "Content-Length" =     (
        319
    );
    "Content-Type" =     (
        "application/json; charset=UTF-8"
    );
    Date =     (
        "Fri, 08 Oct 2021 15:53:55 GMT"
    );
    Server =     (
        ESF
    );
    Vary =     (
        Origin,
        "X-Origin",
        Referer
    );
    "x-content-type-options" =     (
        nosniff
    );
    "x-frame-options" =     (
        SAMEORIGIN
    );
    "x-xss-protection" =     (
        0
    );
} }, body: {
  "error": {
    "code": 403,
    "message": "Requests to this API firebaseinstallations.googleapis.com method google.firebase.installations.v1.FirebaseInstallationsService.CreateInstallation are blocked.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_SERVICE_BLOCKED",
        "domain": "googleapis.com",
        "metadata": {
          "service": "firebaseinstallations.googleapis.com",
          "consumer": "projects/xxxxxxxx"
        }
      }
    ]
  }
}
.
2021-10-08 17:53:55.956881+0200 App[1217:592412] 8.8.0 - [Firebase/Installations][I-FIS002003] Firebase Installation registration failed for app with name: __FIRAPP_DEFAULT, error:
The server responded with an error: 
 - URL: https://firebaseinstallations.googleapis.com/v1/projects/centrix-xxxx/installations/ 
 - HTTP status code: 403 
 - Response body: {
  "error": {
    "code": 403,
    "message": "Requests to this API firebaseinstallations.googleapis.com method google.firebase.installations.v1.FirebaseInstallationsService.CreateInstallation are blocked.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_SERVICE_BLOCKED",
        "domain": "googleapis.com",
        "metadata": {
          "service": "firebaseinstallations.googleapis.com",
          "consumer": "projects/xxxxxx"
        }
      }
    ]
  }
}

Please make sure you use valid GoogleService-Info.plist

2021-10-08 17:53:56.607190+0200 App[1217:592412] 8.8.0 - [Firebase/Messaging][I-FCM023012] Provisioning profile has specifically provisioned devices, most likely a Dev profile.
2021-10-08 17:53:56.607298+0200 App[1217:592412] 8.8.0 - [Firebase/Messaging][I-FCM023013] APNS Environment in profile: development
2021-10-08 17:53:56.608174+0200 App[1217:592412] 8.8.0 - [Firebase/Messaging][I-FCM043000] Info is not found in Keychain. OSStatus: -25300. Keychain query: {
    acct = "com.xxxxxxx.centrix";
    class = genp;
    gena = "com.google.iid-tokens";
    "m_Limit" = "m_LimitAll";
    "r_Attributes" = 1;
    "r_Data" = 1;
}
2021-10-08 17:53:56.609328+0200 App[1217:592415] 8.8.0 - [Firebase/Installations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
2021-10-08 17:53:56.609774+0200 App[1217:592415] 8.8.0 - [Firebase/Installations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
2021-10-08 17:53:56.609862+0200 App[1217:592415] 8.8.0 - [Firebase/Messaging][I-FCM034000] Fetch new token for authorizedEntity: xxxxxx, scope: *
2021-10-08 17:53:56.611530+0200 App[1217:592415] 8.8.0 - [Firebase/Installations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
2021-10-08 17:53:56.612286+0200 App[1217:592412] 8.8.0 - [Firebase/Installations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
⚡️  TO JS {"error":"The operation couldn’t be completed. Too many server requests."}
⚡️  [log] - {"error":"The operation couldn’t be completed. Too many server requests."}

Other Technical Details

Ionic:

   Ionic CLI                     : 6.17.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.8.2
   @angular-devkit/build-angular : 12.1.4
   @angular-devkit/schematics    : 12.2.9
   @angular/cli                  : 12.1.4
   @ionic/angular-toolkit        : 4.0.0

Capacitor:

   Capacitor CLI      : 3.2.4
   @capacitor/android : 3.2.4
   @capacitor/core    : 3.2.4
   @capacitor/ios     : 3.2.4

Utility:

   cordova-res : 0.15.3
   native-run  : 1.4.1

System:

   NodeJS : v14.18.0 (/usr/local/bin/node)
   npm    : 7.24.2
   OS     : macOS Big Sur

Additional Context

I have also tried adding the 2 functions to the AppDelegate.swift as mentioned in the plugin documentation. In this case it returns a token but it seems that it is the deviceToken that does not work for me for notifications either.

I hope it isn't a bug but I report anyway just in case.

WaseemRakab commented 2 years ago

having the same bug here, using firebase 9 with angular fire 7

Ionitron commented 2 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

Sampath-Lokuge commented 2 years ago

You need to add GoogleService-Info.plist through XCode tool. i.e. it doesn't detect if you'll add it through the file system.

RidClick commented 2 years ago

You need to add GoogleService-Info.plist through XCode tool. i.e. it doesn't detect if you'll add it through the file system.

I added it by right clicking the application folder and hitting "Add files to App" and then checking the destination "Copy items if needed", and it still doesn't work

RidClick commented 2 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

At this moment I do not have enough time to make a test application with a Firebase connection to test this, for this reason I opened this issue specifying that I have followed your guide step by step. I need to finish my application and change my notification service to OneSignal, thing I didn't want to do, because of this. But when I have enught time I will, meanwhile I'll wait to someone find the way to resolve this.

Ionitron commented 2 years ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Ionitron 💙

ionitron-bot[bot] commented 2 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.