commit e3b1122dfeb2533ac89bd2cf75ab47bcdcb01c7f
parent 610da0c09c737c6464f3018ddb39760ce8e71ffd
Author: Matthew Horan <matt@matthoran.com>
Date: Thu, 17 Sep 2020 21:00:05 -0400
Use new notification API
Diffstat:
3 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/package.json b/package.json
@@ -11,6 +11,7 @@
"@types/lodash": "^4.14.106",
"date-fns": "^1.29.0",
"expo": "^38.0.0",
+ "expo-notifications": "~0.3.3",
"js-sha256": "^0.9.0",
"lodash": "^4.17.5",
"react": "16.11.0",
diff --git a/src/lib/helpers/push-notifications.ts b/src/lib/helpers/push-notifications.ts
@@ -1,4 +1,4 @@
-import { Notifications } from 'expo';
+import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
export const registerForPushNotificationsAsync = async () => {
@@ -16,18 +16,19 @@ export const registerForPushNotificationsAsync = async () => {
}
export const getPushNotificationStatusAsync = async () => {
- const { status: existingStatus } = await Permissions.getAsync(
- Permissions.NOTIFICATIONS
- );
- let finalStatus = existingStatus;
-
- // Stop here if the user did not grant permissions
- if (finalStatus !== 'granted') {
- return;
+ let token;
+ if (Constants.isDevice) {
+ const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
+ let finalStatus = existingStatus;
+ if (existingStatus !== 'granted') {
+ const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
+ finalStatus = status;
+ }
+ if (finalStatus !== 'granted') {
+ return;
+ }
+ token = (await Notifications.getExpoPushTokenAsync()).data;
}
- // Get the token that uniquely identifies this device
- let token = await Notifications.getExpoPushTokenAsync();
-
return token;
}
diff --git a/yarn.lock b/yarn.lock
@@ -2698,6 +2698,11 @@ badgin@^1.1.2:
resolved "https://registry.yarnpkg.com/badgin/-/badgin-1.1.4.tgz#5a8e2b81e812d3c4af7bacc2e62b36a9a5e40de5"
integrity sha512-BQ1m7TA7IehXb3/9b3cNH6TwIKcdqqJa/E4Z4fO40tSs6HPZWopPvx9QgHeUEd6Aays1BxQXjBpO+yrSYuRSOw==
+badgin@^1.1.5:
+ version "1.1.8"
+ resolved "https://registry.yarnpkg.com/badgin/-/badgin-1.1.8.tgz#6e4c930554945d31752e5de2d8a316036dccda5e"
+ integrity sha512-EGbhb5OwZreHS0vd8tFLzdWBqvz3dFREf1sYK5EtivtTDUkYCLSEKz1KvXJ4MBHAyKGDymx8wYPCQwrftQBifw==
+
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -3734,6 +3739,11 @@ expect@^25.5.0:
jest-message-util "^25.5.0"
jest-regex-util "^25.2.6"
+expo-application@~2.2.1:
+ version "2.2.1"
+ resolved "https://registry.yarnpkg.com/expo-application/-/expo-application-2.2.1.tgz#f14b83ae0b07e4922850f8856a56f141c168d6d0"
+ integrity sha512-YyYB2EPWmFmXgmnul9AMdZ6Ze290BWaez7RhUfAMq2gQU84EdpvL3vkO9SV5E4zI7Rj2jfS0VcCDpxrcdlBW/w==
+
expo-asset@~8.1.7:
version "8.1.7"
resolved "https://registry.yarnpkg.com/expo-asset/-/expo-asset-8.1.7.tgz#32618e51f85df56f1d7dd54c71eb486ae7f7674e"
@@ -3745,7 +3755,7 @@ expo-asset@~8.1.7:
path-browserify "^1.0.0"
url-parse "^1.4.4"
-expo-constants@~9.1.1:
+expo-constants@9.1.1, expo-constants@~9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/expo-constants/-/expo-constants-9.1.1.tgz#bca141ee3d4550e308798128f66c6d9c6a206ca1"
integrity sha512-zCa/wRARODHd6BSwxjBhidmao0AqQnKmLkl0tsVIoZlRyPDHsEaxNR/m+7wqGC7qiC+UpG1qRnvLOLwCGt2ihg==
@@ -3803,6 +3813,16 @@ expo-location@~8.2.1:
dependencies:
invariant "^2.2.4"
+expo-notifications@~0.3.3:
+ version "0.3.3"
+ resolved "https://registry.yarnpkg.com/expo-notifications/-/expo-notifications-0.3.3.tgz#3c7b7275516028853e02f5c796e3365d4fb572ad"
+ integrity sha512-iBqvlbB6UVkU5yF4W9K/sqdPIbJ52VVeL7543G4IA3ARWhx6wdhfzcuGTCtUgV0XmkJu7vmPs+sC31aXjRa0Kg==
+ dependencies:
+ badgin "^1.1.5"
+ expo-application "~2.2.1"
+ expo-constants "9.1.1"
+ uuid "^3.4.0"
+
expo-permissions@~9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-9.0.1.tgz#dc10b58654bbe39bbbed5827369942b01b08055e"