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