1 00:00:02,140 --> 00:00:05,149 So now we know how to trigger, display, and handle 2 00:00:05,149 --> 00:00:07,092 local notifications. 3 00:00:07,092 --> 00:00:09,285 This is an important prerequisite 4 00:00:09,285 --> 00:00:11,866 because with push notifications, 5 00:00:11,866 --> 00:00:16,322 we are going to trigger local notifications, 6 00:00:16,322 --> 00:00:18,540 but that's the difference, 7 00:00:18,540 --> 00:00:22,183 the trigger is not coming from inside our app 8 00:00:22,183 --> 00:00:24,650 like it currently does, 9 00:00:24,650 --> 00:00:27,030 keep in mind, that currently in the end, 10 00:00:27,030 --> 00:00:30,350 we trigger our local notification here 11 00:00:30,350 --> 00:00:32,860 with the trigger notification handler 12 00:00:32,860 --> 00:00:35,950 with the schedule notification async method. 13 00:00:35,950 --> 00:00:39,020 That's how we currently trigger the notification. 14 00:00:39,020 --> 00:00:41,483 And that will no longer be the case. 15 00:00:43,680 --> 00:00:46,267 Instead now with push notifications, 16 00:00:46,267 --> 00:00:51,150 the trigger will be outside of our application. 17 00:00:51,150 --> 00:00:53,280 It could be the developer of the app 18 00:00:53,280 --> 00:00:55,970 manually sending push notifications. 19 00:00:55,970 --> 00:00:57,341 It could be server side code 20 00:00:57,341 --> 00:01:00,630 that leads to a push notification being sent. 21 00:01:00,630 --> 00:01:04,057 For example, when a new chat message is stored in a database 22 00:01:04,057 --> 00:01:05,510 and therefore now, 23 00:01:05,510 --> 00:01:09,140 we will need to learn how we can send push notifications 24 00:01:09,140 --> 00:01:14,080 to other devices and not just to our own device. 25 00:01:14,080 --> 00:01:18,080 For that, we need to understand how push notifications work. 26 00:01:18,080 --> 00:01:20,600 We got our app, and typically of course, 27 00:01:20,600 --> 00:01:24,403 it runs on multiple devices for multiple users. 28 00:01:26,020 --> 00:01:27,780 Then, we got some event 29 00:01:27,780 --> 00:01:31,410 that should lead to a push notification to be delivered. 30 00:01:31,410 --> 00:01:34,160 That could be a chat message that's being posted, 31 00:01:34,160 --> 00:01:37,800 but it could also be that we, as the owner of the app, 32 00:01:37,800 --> 00:01:40,030 decide to send a marketing message 33 00:01:40,030 --> 00:01:42,859 or anything like that to our users. 34 00:01:42,859 --> 00:01:46,907 So we want to deliver our message or our notification 35 00:01:46,907 --> 00:01:48,630 to a device, 36 00:01:48,630 --> 00:01:50,620 but this is not how it works. 37 00:01:50,620 --> 00:01:54,440 We can't directly send messages to devices. 38 00:01:54,440 --> 00:01:56,310 That's a security mechanism 39 00:01:56,310 --> 00:01:59,710 because if anyone could just start sending 40 00:01:59,710 --> 00:02:03,110 push notifications to random devices out there, 41 00:02:03,110 --> 00:02:05,360 our phones would get spammed. 42 00:02:05,360 --> 00:02:09,270 So instead, to deliver push notifications to our apps 43 00:02:09,270 --> 00:02:10,960 on our devices, 44 00:02:10,960 --> 00:02:14,890 we have to use official push notification servers. 45 00:02:14,890 --> 00:02:19,430 And both Android, as well as iOS, so Google and Apple, 46 00:02:19,430 --> 00:02:22,250 have their own push notification servers. 47 00:02:22,250 --> 00:02:25,810 And you have to use those to deliver your message 48 00:02:25,810 --> 00:02:27,140 to the devices. 49 00:02:27,140 --> 00:02:28,030 Why? 50 00:02:28,030 --> 00:02:32,820 Because those servers will only deliver messages to devices 51 00:02:32,820 --> 00:02:34,029 and app installations 52 00:02:34,029 --> 00:02:36,920 that identified themselves. 53 00:02:36,920 --> 00:02:40,850 Essentially, your app will have to identify itself 54 00:02:40,850 --> 00:02:42,885 with Google's and Apple's servers, 55 00:02:42,885 --> 00:02:44,938 it will get a unique token, 56 00:02:44,938 --> 00:02:47,200 an ID you could say, 57 00:02:47,200 --> 00:02:50,400 and only that ID can then later be used 58 00:02:50,400 --> 00:02:52,166 to deliver a push notification 59 00:02:52,166 --> 00:02:55,033 through those official push servers 60 00:02:55,033 --> 00:02:57,410 to your app installations, 61 00:02:57,410 --> 00:02:59,966 because then the official servers can verify 62 00:02:59,966 --> 00:03:04,966 that your app opted into getting those push notifications. 63 00:03:05,090 --> 00:03:06,949 That's the security mechanism here. 64 00:03:06,949 --> 00:03:10,020 And therefore, instead of directly sending messages 65 00:03:10,020 --> 00:03:11,210 to devices, 66 00:03:11,210 --> 00:03:13,580 we, in the end, use that event 67 00:03:13,580 --> 00:03:15,764 in conjunction with those official servers 68 00:03:15,764 --> 00:03:18,004 to send our push notification 69 00:03:18,004 --> 00:03:20,770 through those official push servers 70 00:03:20,770 --> 00:03:23,970 to the different devices we want to target. 71 00:03:23,970 --> 00:03:26,510 That's how push notifications work. 72 00:03:26,510 --> 00:03:29,820 So we have that extra security step in between, 73 00:03:29,820 --> 00:03:31,027 which matters. 74 00:03:31,027 --> 00:03:33,719 Now let's see how we can implement that in code 75 00:03:33,719 --> 00:03:38,073 and how, again, Expo helps us a lot with that.