Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@capacitor/push-notifications] FCM Token received invalid when app deployed via Play Console or Apple Connect #1556

Closed
morsagmon opened this issue Apr 24, 2023 · 5 comments

Comments

@morsagmon
Copy link

morsagmon commented Apr 24, 2023

Bug Report

Plugin(s)

@capacitor/push-notifications 4.1.2
@capacitor/core 4.7.3
@angular/fire 7.5.0
@ionic/angular 7.0.2

Capacitor Version

Capacitor Doctor:

Latest Dependencies:

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

Installed Dependencies:

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

Platform(s)

iOS
Android
Angular

Current Behavior

When I deploy my app directly from Android Studio locally to Android devices, the token I receive and use for sending notification is OK.

However, when the same App is deployed to the Google Play or to Apple Connect (TestFlight) and installed by the testers from Google Play or TestFlight on their devices - the token received is invalid. It also does not look like a token: it is much shorter and has only all-caps chars. Naturally, notifications fail on these devices (Google log screenshot attached here).

I print the received token immediately to the console, before I take it for DB storage, consider this console.log command in the registration process:

PushNotifications.addListener("registration", (token: Token) => {      
      if (token && !this.tokenProcessed) {
        this.tokenProcessed = true;
        console.log('My token: ' + JSON.stringify(token));
        this.onFCMTokenChanged.next(token.value);
      }
    });

This is the console.log output with the weird token received:

My token: {"value":"D8636BCC62A673B4D574736AFCA1F73AF7C34EBBB7D99A38E05CDB6963FEAE8B"}

On a device with local deployment from Android Studio, the (working) token received looks like this:

My token: {"value":"c0qi_fp5QxmILTqsPVkYXv:APA91bFVDfv_EX8RjC5uB23p9Sb--1tYj4Piob2tuGgslcib8aKLAfFKKlCr7EFcZp7p05Rjb8WwY4X-aHMr-1DDUTDbR_MABTuAr4snxdAWGTwihx7I8VHuCa1VNHcdYU0DnWj33YvP"}

Please help me understand and fix this weird behavior - happening only when the app is deployed through Google Play or Apple Connect.

Expected Behavior

Token received from FCM should be exactly the same and a valid one regardless of the app deployment path - locally from Android Studio / XCode or through the App Store / Google Play.

Other Technical Details

My Angular service code registering with FCM looks like this:

import { Injectable, NgZone } from "@angular/core";
import {
  ActionPerformed,
  PushNotifications,
  PushNotificationSchema,
  Token,
} from "@capacitor/push-notifications";
import { Capacitor } from "@capacitor/core";
import { getLocal, setLocal } from "./storage.service";
import { BehaviorSubject } from "rxjs";
import { App } from "@capacitor/app";
import { Router } from "@angular/router";
import { ToastAlertService } from "./toast-alert.service";

@Injectable({
  providedIn: "root",
})
export class FbNotificationsService {
  onFCMTokenChanged: BehaviorSubject<string> = new BehaviorSubject(""); //Listened to in app.component
  onAppResume: BehaviorSubject<string> = new BehaviorSubject(""); //Listened to in chat.page
  tokenProcessed: boolean = false;

  constructor(private taService: ToastAlertService, private zone: NgZone, private route: Router) { }

  initPush() {
    if (Capacitor.getPlatform() !== "web") {
      this.registerPush();
    } else {
      this.onFCMTokenChanged.next("web-platform");
    }
  }

  private registerPush() {
    PushNotifications.requestPermissions().then((permission) => {
      if (permission.receive === "granted") {
        console.log('FireBase Permission granted');

        PushNotifications.register(); 
      } else {
        console.log('FireBase NO permissions granted');
      }
    });

    PushNotifications.addListener("registration", (token: Token) => {
      if (token && !this.tokenProcessed) {
        this.tokenProcessed = true;
        console.log('My token: ' + JSON.stringify(token));
        this.onFCMTokenChanged.next(token.value);

        setLocal("device-token", token.value); //.then( () => {
      }
    });

    PushNotifications.addListener("registrationError", (error: any) => {
      console.log('Registration Error: ' + JSON.stringify(error));
      this.taService.dialogClose(
        "Network Error",
        "The network signal is not sufficient at this time. Please improve connection and try again"
      );
      App.exitApp();
    });

Additional Context

I tried the Google Firebase support, but as I'm not using their FCM SDK, they are not helpful.

fcm-error

@mghcs87
Copy link

mghcs87 commented Apr 26, 2023

@morsagmon Check this, it worked well for me: Guide

@spycedev
Copy link

Any solution to this beside using a different plugin? I'm getting the same issue on iOS in development.

The token return is not a valid Firebase token

@Ionitron
Copy link
Collaborator

This issue needs more information before it can be addressed.
In particular, the reporter needs to provide a minimal sample app that demonstrates the issue.
If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks!
Ionitron 💙

@Ionitron
Copy link
Collaborator

Ionitron commented Sep 7, 2023

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
Copy link

ionitron-bot bot commented Sep 22, 2023

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants