-: Here in this van block, 2 2
we now know that we do have granted permissions. 3 3
That's the only scenario where we will reach 4 4
this van block in the end. 5 5
And therefore now here, 6 6
we want to sign up with Expo's push service, 7 7
which under the hood, 8 8
will ensure that those official services get used. 9 9
And for that, we can again use that notifications package, 10 10
which we imported, this one from Expo notifications. 11 11
And there we can call get Expo push token async. 12 12
This is a method that will talk to Expo's server. 13 13
So not to Google's and Apple's server 14 14
but to dead server owned and managed by the Expo team, 15 15
so to say, and when I say team, by the way, 16 16
that's not just two people working on that. 17 17
This is a reliable service backed by a big community. 18 18
So we'll talk to that server there. 19 19
And we'll sign up our app with that Expo server. 20 20
And then behind the scenes, 21 21
Expo this server ends on 22 22
will know how to deliver push notifications 23 23
to the different app installations on the different devices. 24 24
So we just need to call that and return the result. 25 25
Since this will return a promise, 26 26
and then in the next van block, 27 27
thereafter, we'll get that result. 28 28
So here we'll get some data. 29 29
And for the moment, 30 30
let's simply log that data to see what's inside there. 31 31
Now, if we save that, we'll have a problem though, 32 32
we can do this, but this won't work on those simulators. 33 33
If we try to run this on the Apple device, 34 34
on the iOS simulator, 35 35
if I run the project again there, we'll see that ultimately, 36 36
nothing is being printed here. 37 37
The same for Android, if I quit that, 38 38
and restarted on Android 39 39
we'll not see any output there as well. 40 40
So we're not able to test this on simulators. 41 41
Instead, we'll need real devices. 42 42
And I'll start with a real iPhone. 43 43
So I'm going to quit this Expo server 44 44
and restarted with my real iPhone connected. 45 45
And now I scan the QR code with my iPhone. 46 46
Now I did actually run the app there before, 47 47
I have to admit, 48 48
that's why I'm not getting prompted 49 49
for providing permissions here. 50 50
I did have to do that before. 51 51
So you should be prompted. 52 52
And now there, with that connected, 53 53
we should be able to analyze whether everything works. 54 54
For that, let's first of all add a console log here 55 55
getting token to see whether this works 56 56
whenever we're trying to get the token. 57 57
And we do, getting token is being printed here. 58 58
Now still, we don't see the console log here for the data. 59 59
We get back when we request the token. 60 60
So let's add a console log here in the catch function 61 61
to see whether we got an error. 62 62
And indeed, we did get an error, 63 63
an API error that the Expo push notification service 64 64
is supported only for Expo projects 65 65
so that we need to be logged in our Expo developer account 66 66
on the computer from which we are loading the project, 67 67
and that's not the case for me here. 68 68
I'm not logged into my Expo developer account. 69 69
Now getting an Expo developer account is free. 70 70
You just need to sign up with Expo to get such an account. 71 71
And once you do have that account, 72 72
you can quit that Expo server and run Expo log in there. 73 73
And now you'll need to log in with the account 74 74
you just created. 75 75
And once you did log in, 76 76
you can start the Expo server again and reload the Expo app 77 77
on your iPhone or Android device as well. 78 78
And once you do that, once the app starts 79 79
on your real device, you should see that you now get 80 80
a log where the data that we log here 81 81
is actually such an object with a data field, 82 82
which holds that exponent push token value here. 83 83
And that's the token we'll need 84 84
to deliver push notifications to the different devices. 85 85
And what I just showed on my real iPhone 86 86
will work in exactly the same way on a real Android device. 87 87
So now let me show you how we can use that push token 88 88
to deliver push notifications.