Closed lesliedizon-kano closed 1 year ago
I can't see anything wrong with the composition of the message, but you're using 5.26.0 of the SDK, perhaps an update to 5.26.4 (the last version in the 5.x branch) can help.
I recommend upgrading to 7.x, or at least 6.x if you don't have access to PHP 8.1 yet. If there's a bug in the messaging component, there's a chance it might be fixed in the newer releases.
If you have an FCM message payload from somewhere else that you know works, you can json_encode()
the the message and compare them.
You can also use a payload you know works in a RawMessageFromArray
object and see if that works.
Finally, there's a chance that there's either a server-side problem in the communication between FCM and Apple, or a hiccup in one of the servers which prevent the message from being delivered - in that case, the problem might resolve itself with time.
Aside from that I can't provide free support for older releases than the current one, I hope you can understand 🙏🏻.
Hi Jerome, thank you for your response.
I would like to ask, is it ideal to have both the Android and iOS in one function or should I separate them?
The optimal way should be to include them both in the same message - that saves you one request, and it's officially supported by FCM.
But if the problem doesn't occur if you separate the messages, I(!) would be pragmatic and do it this way if it works 😅. Just keep in mind that you must then include only the specific configuration, not the Notification
at the root level of the message.
You should definitely test it this way, let me know how it goes!
I have updated to the 6.9.5 version of kreait/firebase-php and I am getting this error Expected type 'Psr\Cache\CacheItemPoolInterface'. Found 'Psr\SimpleCache\CacheInterface'
when trying to use the withVerifierCache method.
<?php
namespace Kano\Fubar\Service;
use Kano\Fubar\FubarApp;
use Kano\Fubar\Singleton;
use Kreait\Firebase;
use Kreait\Firebase\Contract\Database;
use Kreait\Firebase\Factory;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Simple\FilesystemCache;
use Kano\Fubar\Log\Logger;
/**
* Manages a few utility components for dealing with Firebase through the kreait/firebase-php library.
*
* Primary use of this class is to fetch the $firebase object via FirebaseService::getInstance()->getFirebase();
*/
class FirebaseService extends Singleton
{
private $firebaseSdk;
private $keyCache;
private $serviceAccount;
public function getFirebaseProjectId(): string
{
return getenv('FIREBASE_PRODUCT_ID');
}
public function getFirebase(): Database
{
if ($this->firebaseSdk == null)
{
$this->firebaseSdk = (new Factory())
->withServiceAccount($this->getServiceAccount())
->withVerifierCache($this->getKeyCache())
->createDatabase();
}
return $this->firebaseSdk;
}
/**
* Currently returns a FileSystemCache object from the Symfony libraries.
*
* @return CacheInterface Cache object for storing public keys
*/
public function getKeyCache(): CacheInterface
{
// @see https://firebase.google.com/docs/auth/admin/verify-id-tokens
// @see https://symfony.com/doc/current/components/cache/adapters/filesystem_adapter.html
if ($this->keyCache == null)
{
$this->keyCache = new FilesystemCache(getenv('KANO_GAME') . '-firebase');
}
return $this->keyCache;
}
public function setKeyCache(CacheInterface $cache)
{
$this->keyCache = $cache;
}
/**
* @return ServiceAccount object required to deal with Firebase
*/
public function getServiceAccount(): string
{
if ($this->serviceAccount == null)
{
// @see https://firebase.google.com/docs/admin/setup for more on the json file required here
$this->serviceAccount = FubarApp::ROOT_DIR . '/config/' . $this->getFirebaseProjectId() . '-google-service-account.json';
}
return $this->serviceAccount;
}
}
The SDK needs a PSR-6 Cache implementation, but you provided a PSR-16 Cache implementation. This was a change in 6.0 (https://github.com/kreait/firebase-php/blob/6.x/CHANGELOG.md at the bottom). You can wrap the PSR-16 cache in a PSR-6 adapter, for example with the symfony/cache
component (https://symfony.com/doc/current/components/cache/psr6_psr16_adapters.html)
Describe the bug
The code that I have pasted below doesn't work when I am trying to send it to an iOS device through a topic subscription. To be exact,
$messaging->send($message);
is what I use to trigger this code which is also the same call where my Android config is and my Android device would receive it right away. I can verify and see that my user for the iOS device is subscribed to the topic the same way my android device user is.Here is the code block I use for sending the topic notification:
Installed packages
PHP version and extensions
Steps to reproduce the issue.
Error message/Stack trace
Additional information
No response