Git Product home page Git Product logo

Comments (8)

brozot avatar brozot commented on June 26, 2024

Hi
I think it Missing an import of Laravel-FCM\Response\DownstreamResponse somewhere in the code.

Can you give me more informations about this error.
Maybe with a part of your code that thrown the exception.

Thanks

from laravel-fcm.

tarhe avatar tarhe commented on June 26, 2024

$downstreamResponse = FCM::sendTo($tokens, $option, $notification);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

//return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

//return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();

//return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:errror) - in production you should remove from your database the tokens present in this array
$downstreamResponse->tokensWithError();

from laravel-fcm.

tarhe avatar tarhe commented on June 26, 2024

I commented out those lines apart from the first one and it worked.

from laravel-fcm.

brozot avatar brozot commented on June 26, 2024

I am unable to reproduce your problem

Do you use Laravel or Lumen?
Can you give me all the content of the error message?

from laravel-fcm.

gcphost avatar gcphost commented on June 26, 2024

This is related to not having the use statement for LaravelFCM\Response\DownstreamResponse (as you said, not imported).

The readme is missing them in some of the other examples, I only updated one.

from laravel-fcm.

tarhe avatar tarhe commented on June 26, 2024

I am using Laravel 5.2

Notifications are sent but it produce errors on my laravel.log and I found these lines of codes are the ones causing it:

        $downstreamResponse = new DownstreamResponse($response, $tokens);
        $downstreamResponse->numberSuccess();
        $downstreamResponse->numberFailure();
        $downstreamResponse->numberModification();

        //return Array - you must remove all this tokens in your database
        $downstreamResponse->tokensToDelete(); 

        //return Array (key : oldToken, value : new token - you must change the token in your database )
        $downstreamResponse->tokensToModify(); 

        //return Array - you should try to resend the message to the tokens in the array
        $downstreamResponse->tokensToRetry();

This was the error:

[2016-07-22 09:10:28] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Api\V1\Controllers\DownstreamResponse' not found' in C:\wamp\www\MyApp\app\Api\V1\Controllers\PushNotificationController.php:42

After I did what @gcphost recommended (use LaravelFCM\Response\DownstreamResponse;), I got the following error:

[2016-07-22 09:11:39] local.ERROR: exception 'ErrorException' with message 'Undefined variable: response' in C:\wamp\www\MyApp\app\Api\V1\Controllers\PushNotificationController.php:42

Sorry, what does those lines of code do, I mean what are their functions.

from laravel-fcm.

brozot avatar brozot commented on June 26, 2024

Hi,

I think that your error is thrown by the following line:

$downstreamResponse = new DownstreamResponse($response, $tokens); 

You shouldn't instantiate DownstreamReponse in your controller.

DownstreamResponse is constructed by the package and is returned by the method: FCM::sendTo($tokens, $option, $notification);

Like in the following line:

$downstreamResponse = FCM::sendTo($tokens, $option, $notification);

In summary,

  1. You send a notification with the method FCM::sendTo($tokens, $option, $notification);.
  2. The package is sending the notification and constructs a DownstreamResponse with the response returned by fcm.
  3. In your controller, you can check if the notification was send with success or if some error appeared during the process, with the following methods:
    $downstreamResponse->numberSuccess(), $downstreamResponse->numberFailure(); and $downstreamResponse->numberModification();
  4. You can get all tokens that you must to remove in your database with the method: $downstreamResponse->tokensToDelete();
  5. You can get all tokens that you must to modify in your database with the method: $downstreamResponse->tokensToModify();
  6. You can all tokens that you should resend with this method: $downstreamResponse->tokensToRetry();

Please can you give me a feedback if this solution is working for you.

Best Regards

from laravel-fcm.

tarhe avatar tarhe commented on June 26, 2024

Thanks for the detailed explanation, it works well now. Thanks

from laravel-fcm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.