kreait / firebase-bundle

A Symfony Bundle for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
135 stars 25 forks source link

[Possible Bug] sendMulticast isn't working anymore. #50

Closed MarkDaleman closed 1 year ago

MarkDaleman commented 1 year ago

Describe the bug

Sending a single message works just fine. for example:

$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
    'title' => $title,
    'body' => $body,
]);

$message = CloudMessage::withTarget('token', 'my-single-device-token')
    ->withNotification($notification)
    ->withData($data);
;
$messaging->send($message);

The above example is able to send a notification to my phone device, nice!

However, sending with sendMulticast doesn't work. I've tried it like this:

$deviceTokens = ['my-single-device-token'];
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
    'title' => $title,
    'body' => $body,
]);
$message = CloudMessage::new();
$message->withNotification($notification);

$report = $messaging->sendMulticast($message, $deviceTokens);

The report yields:

Successful sends: 1
Failed sends: 0

The report says that the notification is sent, however nothing happens on my phone..

Installed packages

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=7.4",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-json": "*",
        "cocur/slugify": "^4.3",
        "doctrine/annotations": "^1.14",
        "doctrine/doctrine-bundle": "^2.10",
        "doctrine/doctrine-migrations-bundle": "^3.2",
        "doctrine/orm": "^2.15",
        "friendsofphp/php-cs-fixer": "^3.13",
        "gesdinet/jwt-refresh-token-bundle": "^1.1",
        "knpuniversity/oauth2-client-bundle": "^2.15",
        "kreait/firebase-bundle": "^4.1",
        "league/fractal": "^0.20.1",
        "league/oauth2-google": "^4.0",
        "lexik/jwt-authentication-bundle": "^2.19",
        "nelmio/api-doc-bundle": "^4.11",
        "notfloran/mjml-bundle": "^3.7",
        "patrickbussmann/oauth2-apple": "^0.2.10",
        "predis/predis": "^2.1",
        "ramsey/uuid-doctrine": "^2.0",
        "sensio/framework-extra-bundle": "^6.2",
        "sentry/sentry-symfony": "^4.7",
        "symfony/asset": "5.4.*",
        "symfony/console": "5.4.*",
        "symfony/dotenv": "5.4.*",
        "symfony/flex": "^1.17|^2",
        "symfony/form": "5.4.*",
        "symfony/framework-bundle": "5.4.*",
        "symfony/mailer": "5.4.*",
        "symfony/runtime": "5.4.*",
        "symfony/security-bundle": "5.4.*",
        "symfony/security-csrf": "5.4.*",
        "symfony/twig-bundle": "5.4.*",
        "symfony/uid": "5.4.*",
        "symfony/validator": "5.4.*",
        "symfony/yaml": "5.4.*",
        "symfonycasts/reset-password-bundle": "^1.17",
        "symfonycasts/verify-email-bundle": "^1.13"
    },
    "require-dev": {
        "phpstan/phpstan": "^1.10",
        "phpstan/phpstan-doctrine": "^1.3",
        "phpstan/phpstan-symfony": "^1.2",
        "rector/rector": "^0.15.24",
        "symfony/maker-bundle": "^1.43",
        "symfony/stopwatch": "5.4.*",
        "symfony/web-profiler-bundle": "5.4.*"
    },
    "config": {
        "allow-plugins": {
            "composer/package-versions-deprecated": true,
            "symfony/flex": true,
            "symfony/runtime": true,
            "phpstan/extension-installer": true,
            "php-http/discovery": true
        },
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd"
        },
        "cs": "php-cs-fixer fix --ansi -v",
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ],
        "phpstan": [
          "phpstan analyse src"
        ],
        "rector": [
          "vendor/bin/rector process src"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.4.*",
            "docker": false
        }
    }
}

PHP version and extensions

php 7.4.33 The PHP interpreter

Steps to reproduce the issue.


$deviceTokens = ['my-single-device-token'];
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
    'title' => $title,
    'body' => $body,
]);
$message = CloudMessage::new();
$message->withNotification($notification);

$report = $messaging->sendMulticast($message, $deviceTokens);

Error message/Stack trace

-

Additional information

No response

jeromegamez commented 1 year ago

I don't support this version of the package anymore (the package version is not current, the underlying SDK version is not supported anymore, and the PHP version is not supported anymore), also the way of sending multicast messages in this version has been deprecated by Firebase.

The current version of the SDK uses a different method to send the same message to different devices, that should work because it uses the same endpoint for sending a message to a single or multiple devices.

if possible, please update to the latest version. If that's not possible. If it isn't possible, see https://github.com/kreait/firebase-php#support-for-older-versions-of-the-sdk - backporting the new method of sending the same message to multiple devices would take me approximately 4 hours, so I could do it after a one-time sponsorship of $400.

MarkDaleman commented 1 year ago

Hello @jeromegamez. Thank you very much for the quick reply, appreciate it!

I kinda missed that the support for 7.4.* has been dropped. I think we're going to upgrade this platform to php8.1 and symfony 6.3.3.. since this project is new, that should be fairly easy to do.

Thanks!

jeromegamez commented 1 year ago

It's good to see that the upgrade is possible, thank you for the feedback!

jeromegamez commented 1 year ago

Oh, and let me know if the problem persists!