How to send notification to all Onesignal users with Flutter

Asked

Viewed 98 times

-1

Hello!

I’m learning notifications with flutter and oneSignal. I figured out how to send notifications to specific users, but I don’t know how to send them to multiple users. My code so far is this:

OneSignal.shared.postNotification(OSCreateNotification(
          playerIds: ['e2926936-48d7-46c7-a093-169c19b902ee'],
          content: 'Mensagem de teste',
          heading: 'Acho que esta funcionando'));

In the playerIds is where you put users to send. He expects a list, but searching the internet I saw that to send to all users just leave playerIds empty. I tried this way and could not. I tried these ways: playerIds: []; playerIds: null; playerIds: [''];, I also tried to delete the line, but from the exception all attempts

Anyway, I need you to send notification to all users at once

1 answer

2


In the documentation of the method postNotification says that:

Please note that you must specify at least one Onesignal user ID that the notification should be sent to, using the playerIds Property.

(Free translation: Please note that you need to specify at least one user ID that the notification should be sent using the property playerIds)

That is, there is no such possibility of leaving blank or null to send to everyone. Where did you read this?

The other method postNotificationWithJsonalso expects a list of PlayerIds.

To send a notification to all users, use the Onesignal Dashboard as instructed here:

  • Click on the tab Messages
  • Choose as audience "Subscribed Users" (Which if you haven’t changed represents all subscribed devices)
  • Enter the title, subtitle, message, image and other settings of your notification.
  • Choose other settings like scheduling, extra fields for deep-linking or priority.
  • Press the button "Send"

For a better description of the features see official documentation

  • 1

    Oh yes, I had also read that you need a playerId, https://www.youtube.com/watch?v=HQ7sIhzQGNk, in this video here the Thizer App teaches how to use, and in one of the comments it says 'It’s supposed to work leaving the playerIds empty ;)' in answer the question: How do you send notification to everyone on the flutter?

  • I can send the notification through the Onesignal website, but I would like to send by application, in code you know

  • I believe that the only way will be getting all the playerID to send right?

  • I believe so. Won’t solve, but a tip that might help is you use the function setExternalUserId to associate a more meaningful key to each user.

  • Forgive the delay, as I did not work on the project these days, I ended up not even coming here, so I will study this externalUserId, I think will solve my problem, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.