And now with it all set up,
once it restarted on my device, I can test it there.
Now I will actually here send it to the same device
as I'm running on,
but this could be sent to any other device as well.
I just don't have any second device around right now.
But if I press trigger notification,
you see sent via the app.
Which clearly is that brand new message we prepared.
So that is this push notification
sent through Expo's push servers.
And whilst I sent it to myself here, which of course
might not be what you want to do in most scenarios.
You still see the idea behind it.
This could have been sent to any other application
of which we had the push token.
Now, speaking of that push token, though,
how should you manage that?
Because at the moment you could argue
that the only push token we can know in this application
is the one off this device on which this app is installed.
So ho could we know the push token of some other device?
How could that work?
So we learned that we can leverage Expo push servers
to deliver push notifications.
But we need a push token for that.
That's no problem because we can get that token
as we do it here with get get.ExpoPushTokenAsync.
The problem with that, however, is that,
of course we can get a token with that
and we can store this in state thereafter,
but then we only have to token off this device
on which this app installations running.
So when we later want to send a push notification,
the only token we know is our own token.
Now for this example, this was just what we needed,
but in reality, we of course want to send
a push notification to other devices.
So to the same app installed on other devices
of other users, how would we get their tokens?
Well, just as we get their emails
or whatever else we need in an application.
You can of course write code where once you got that token,
you don't, or maybe not just manage it in your local state,
but instead you send an HTTP request to your own API
where you then have some logic to receive that token
and store it in a database.
This token of course can, and in reality will,
be shared and stored in a database.
So that any user of your app
submits not just his or her email address and password,
but also his or her push token.
And with that data stored in a database on your server,
you can, of course, always retrieve that token
and use it in your app when you need it.
So you can share that token,
just like you share other user data as needed.
After all, if a user creates a product
in a shop application,
we also store that product in a database
to show it to other users as well.
With a token, it's no different.
We won't show it to other users,
but we can still fetch it on the devices of our users
and there use it in the code
to send push notifications as shown here.
In addition, it is worth pointing out that
when it comes to sending notifications,
there is a separate article on the Expo docs,
and you can find it if you search for
Expo push notifications and look for this
Sending Notifications article.
There, you will learn about different ways
of sending notifications.
One way is this way, that you use
Expos push server like this.
This is something you can do
and there is nothing wrong with it.
But if you don't really need to trigger
the push notification from inside the app,
but instead you want to trigger it from
inside your own server.
So now I'm talking about your server,
which you as developer own.
For example, the server where
you also store products users create,
and you wanna trigger a push notification
from on that server, you can do that as well.
The Expo team gives you many SDKs for Node, for Python,
for PHP, which make it very easy to trigger
push notifications on your own server.
Under the hood, those SDKs
will basically do what we do here.
They will send the request to the Expo push server.
Because that Expo push server,
needs to be involved at all times.
So those SDKs will still do that.
But they can take away the need
to run this logic inside of the app,
and instead you could run it on your own server,
if that would be something you needed.
So you can really send push notifications in different ways.
You can use the SDK like this,
you can also just send a request
to this Expo push API, as we did it here,
and that in turn can be done
from inside your app or even from outside of it.
You could use any tool you want
to send a post request with this data, to this URL.
That doesn't have to happen inside of an Expo app.
This is a regular HTTP request.
So whenever you send a request configured like this,
a push notification to that token, which you of course need,
will be delivered.
So that's how you can send push notifications.
And that's how easy it is to get started
with push notifications when you're using Expo.