1 00:00:02,250 --> 00:00:04,170 And now with it all set up, 2 00:00:04,170 --> 00:00:07,880 once it restarted on my device, I can test it there. 3 00:00:07,880 --> 00:00:11,240 Now I will actually here send it to the same device 4 00:00:11,240 --> 00:00:12,301 as I'm running on, 5 00:00:12,301 --> 00:00:15,580 but this could be sent to any other device as well. 6 00:00:15,580 --> 00:00:19,730 I just don't have any second device around right now. 7 00:00:19,730 --> 00:00:22,440 But if I press trigger notification, 8 00:00:22,440 --> 00:00:24,250 you see sent via the app. 9 00:00:24,250 --> 00:00:26,908 Which clearly is that brand new message we prepared. 10 00:00:26,908 --> 00:00:29,220 So that is this push notification 11 00:00:29,220 --> 00:00:32,080 sent through Expo's push servers. 12 00:00:32,080 --> 00:00:36,640 And whilst I sent it to myself here, which of course 13 00:00:36,640 --> 00:00:39,650 might not be what you want to do in most scenarios. 14 00:00:39,650 --> 00:00:42,360 You still see the idea behind it. 15 00:00:42,360 --> 00:00:45,750 This could have been sent to any other application 16 00:00:45,750 --> 00:00:48,149 of which we had the push token. 17 00:00:48,149 --> 00:00:50,990 Now, speaking of that push token, though, 18 00:00:50,990 --> 00:00:52,650 how should you manage that? 19 00:00:52,650 --> 00:00:54,560 Because at the moment you could argue 20 00:00:54,560 --> 00:00:58,235 that the only push token we can know in this application 21 00:00:58,235 --> 00:01:03,220 is the one off this device on which this app is installed. 22 00:01:03,220 --> 00:01:07,080 So ho could we know the push token of some other device? 23 00:01:07,080 --> 00:01:08,860 How could that work? 24 00:01:08,860 --> 00:01:13,060 So we learned that we can leverage Expo push servers 25 00:01:13,060 --> 00:01:15,660 to deliver push notifications. 26 00:01:15,660 --> 00:01:18,250 But we need a push token for that. 27 00:01:18,250 --> 00:01:21,308 That's no problem because we can get that token 28 00:01:21,308 --> 00:01:26,160 as we do it here with get get.ExpoPushTokenAsync. 29 00:01:26,160 --> 00:01:28,380 The problem with that, however, is that, 30 00:01:28,380 --> 00:01:30,520 of course we can get a token with that 31 00:01:30,520 --> 00:01:33,410 and we can store this in state thereafter, 32 00:01:33,410 --> 00:01:36,470 but then we only have to token off this device 33 00:01:36,470 --> 00:01:39,070 on which this app installations running. 34 00:01:39,070 --> 00:01:41,940 So when we later want to send a push notification, 35 00:01:41,940 --> 00:01:44,980 the only token we know is our own token. 36 00:01:44,980 --> 00:01:47,920 Now for this example, this was just what we needed, 37 00:01:47,920 --> 00:01:50,470 but in reality, we of course want to send 38 00:01:50,470 --> 00:01:53,380 a push notification to other devices. 39 00:01:53,380 --> 00:01:56,400 So to the same app installed on other devices 40 00:01:56,400 --> 00:02:00,097 of other users, how would we get their tokens? 41 00:02:00,097 --> 00:02:03,180 Well, just as we get their emails 42 00:02:03,180 --> 00:02:05,542 or whatever else we need in an application. 43 00:02:05,542 --> 00:02:10,210 You can of course write code where once you got that token, 44 00:02:10,210 --> 00:02:15,210 you don't, or maybe not just manage it in your local state, 45 00:02:16,040 --> 00:02:21,040 but instead you send an HTTP request to your own API 46 00:02:21,860 --> 00:02:25,868 where you then have some logic to receive that token 47 00:02:25,868 --> 00:02:28,118 and store it in a database. 48 00:02:28,118 --> 00:02:32,650 This token of course can, and in reality will, 49 00:02:32,650 --> 00:02:35,830 be shared and stored in a database. 50 00:02:35,830 --> 00:02:38,280 So that any user of your app 51 00:02:38,280 --> 00:02:41,950 submits not just his or her email address and password, 52 00:02:41,950 --> 00:02:44,770 but also his or her push token. 53 00:02:44,770 --> 00:02:49,642 And with that data stored in a database on your server, 54 00:02:49,642 --> 00:02:53,150 you can, of course, always retrieve that token 55 00:02:53,150 --> 00:02:55,836 and use it in your app when you need it. 56 00:02:55,836 --> 00:02:58,260 So you can share that token, 57 00:02:58,260 --> 00:03:01,178 just like you share other user data as needed. 58 00:03:01,178 --> 00:03:04,920 After all, if a user creates a product 59 00:03:04,920 --> 00:03:06,800 in a shop application, 60 00:03:06,800 --> 00:03:09,730 we also store that product in a database 61 00:03:09,730 --> 00:03:12,300 to show it to other users as well. 62 00:03:12,300 --> 00:03:14,060 With a token, it's no different. 63 00:03:14,060 --> 00:03:16,160 We won't show it to other users, 64 00:03:16,160 --> 00:03:19,970 but we can still fetch it on the devices of our users 65 00:03:19,970 --> 00:03:21,870 and there use it in the code 66 00:03:21,870 --> 00:03:25,194 to send push notifications as shown here. 67 00:03:25,194 --> 00:03:28,540 In addition, it is worth pointing out that 68 00:03:28,540 --> 00:03:30,698 when it comes to sending notifications, 69 00:03:30,698 --> 00:03:34,462 there is a separate article on the Expo docs, 70 00:03:34,462 --> 00:03:36,610 and you can find it if you search for 71 00:03:36,610 --> 00:03:39,420 Expo push notifications and look for this 72 00:03:39,420 --> 00:03:41,378 Sending Notifications article. 73 00:03:41,378 --> 00:03:44,120 There, you will learn about different ways 74 00:03:44,120 --> 00:03:46,120 of sending notifications. 75 00:03:46,120 --> 00:03:48,820 One way is this way, that you use 76 00:03:48,820 --> 00:03:51,600 Expos push server like this. 77 00:03:51,600 --> 00:03:52,557 This is something you can do 78 00:03:52,557 --> 00:03:54,850 and there is nothing wrong with it. 79 00:03:54,850 --> 00:03:57,410 But if you don't really need to trigger 80 00:03:57,410 --> 00:04:00,330 the push notification from inside the app, 81 00:04:00,330 --> 00:04:02,605 but instead you want to trigger it from 82 00:04:02,605 --> 00:04:04,890 inside your own server. 83 00:04:04,890 --> 00:04:06,960 So now I'm talking about your server, 84 00:04:06,960 --> 00:04:09,000 which you as developer own. 85 00:04:09,000 --> 00:04:11,160 For example, the server where 86 00:04:11,160 --> 00:04:14,000 you also store products users create, 87 00:04:14,000 --> 00:04:16,590 and you wanna trigger a push notification 88 00:04:16,590 --> 00:04:20,110 from on that server, you can do that as well. 89 00:04:20,110 --> 00:04:25,110 The Expo team gives you many SDKs for Node, for Python, 90 00:04:25,150 --> 00:04:29,520 for PHP, which make it very easy to trigger 91 00:04:29,520 --> 00:04:32,900 push notifications on your own server. 92 00:04:32,900 --> 00:04:35,120 Under the hood, those SDKs 93 00:04:35,120 --> 00:04:37,780 will basically do what we do here. 94 00:04:37,780 --> 00:04:41,620 They will send the request to the Expo push server. 95 00:04:41,620 --> 00:04:43,900 Because that Expo push server, 96 00:04:43,900 --> 00:04:46,170 needs to be involved at all times. 97 00:04:46,170 --> 00:04:48,462 So those SDKs will still do that. 98 00:04:48,462 --> 00:04:51,340 But they can take away the need 99 00:04:51,340 --> 00:04:53,900 to run this logic inside of the app, 100 00:04:53,900 --> 00:04:56,470 and instead you could run it on your own server, 101 00:04:56,470 --> 00:04:59,130 if that would be something you needed. 102 00:04:59,130 --> 00:05:02,890 So you can really send push notifications in different ways. 103 00:05:02,890 --> 00:05:05,350 You can use the SDK like this, 104 00:05:05,350 --> 00:05:08,490 you can also just send a request 105 00:05:08,490 --> 00:05:12,370 to this Expo push API, as we did it here, 106 00:05:12,370 --> 00:05:14,100 and that in turn can be done 107 00:05:14,100 --> 00:05:17,110 from inside your app or even from outside of it. 108 00:05:17,110 --> 00:05:19,040 You could use any tool you want 109 00:05:19,040 --> 00:05:23,295 to send a post request with this data, to this URL. 110 00:05:23,295 --> 00:05:26,900 That doesn't have to happen inside of an Expo app. 111 00:05:26,900 --> 00:05:29,330 This is a regular HTTP request. 112 00:05:29,330 --> 00:05:32,310 So whenever you send a request configured like this, 113 00:05:32,310 --> 00:05:36,480 a push notification to that token, which you of course need, 114 00:05:36,480 --> 00:05:38,070 will be delivered. 115 00:05:38,070 --> 00:05:40,720 So that's how you can send push notifications. 116 00:05:40,720 --> 00:05:43,410 And that's how easy it is to get started 117 00:05:43,410 --> 00:05:46,993 with push notifications when you're using Expo.