expo-notifications 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/android/build.gradle +14 -8
  4. package/android/src/main/java/expo/modules/notifications/NotificationsPackage.java +1 -3
  5. package/android/src/main/java/expo/modules/notifications/badge/BadgeModule.kt +37 -0
  6. package/build/NotificationPermissions.d.ts +2 -2
  7. package/build/NotificationPermissions.js +2 -2
  8. package/build/NotificationPermissions.js.map +1 -1
  9. package/build/ServerRegistrationModule.web.d.ts.map +1 -1
  10. package/build/ServerRegistrationModule.web.js +9 -3
  11. package/build/ServerRegistrationModule.web.js.map +1 -1
  12. package/build/presentNotificationAsync.d.ts.map +1 -1
  13. package/build/presentNotificationAsync.js +2 -2
  14. package/build/presentNotificationAsync.js.map +1 -1
  15. package/build/registerTaskAsync.d.ts +2 -2
  16. package/build/registerTaskAsync.js +2 -2
  17. package/build/registerTaskAsync.js.map +1 -1
  18. package/build/scheduleNotificationAsync.js +2 -2
  19. package/build/scheduleNotificationAsync.js.map +1 -1
  20. package/build/setNotificationChannelAsync.d.ts +1 -1
  21. package/build/setNotificationChannelAsync.js +1 -1
  22. package/build/setNotificationChannelAsync.js.map +1 -1
  23. package/package.json +4 -4
  24. package/src/NotificationPermissions.ts +2 -2
  25. package/src/ServerRegistrationModule.web.ts +9 -3
  26. package/src/presentNotificationAsync.ts +2 -2
  27. package/src/registerTaskAsync.ts +2 -2
  28. package/src/scheduleNotificationAsync.ts +2 -2
  29. package/src/setNotificationChannelAsync.ts +1 -1
  30. package/android/src/main/java/expo/modules/notifications/badge/BadgeModule.java +0 -40
  31. package/android/src/main/java/expo/modules/notifications/badge/ExpoBadgeManager.java +0 -44
  32. package/android/src/main/java/expo/modules/notifications/badge/interfaces/BadgeManager.java +0 -7
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.24.0 — 2023-09-15
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
17
+ ## 0.23.0 — 2023-09-04
18
+
19
+ ### 🎉 New features
20
+
21
+ - Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
22
+
23
+ ### 🐛 Bug fixes
24
+
25
+ - Fix server rendering with Metro web. ([#24195](https://github.com/expo/expo/pull/24195) by [@EvanBacon](https://github.com/EvanBacon))
26
+
13
27
  ## 0.22.0 — 2023-08-02
14
28
 
15
29
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -126,7 +126,7 @@ This module requires permission to subscribe to device boot. It's used to setup
126
126
 
127
127
  ### Config plugin setup (optional)
128
128
 
129
- If you're using EAS Build, you can set your Android notification icon and color tint, add custom push notification sounds, and set your iOS notification environment using the expo-notifications config plugin ([what's a config plugin?](https://docs.expo.dev/home/config-plugins/introduction)). To setup, just add the config plugin to the plugins array of your `app.json` or `app.config.js` as shown below, then rebuild the app.
129
+ If you're using EAS Build, you can set your Android notification icon and color tint, add custom push notification sounds, and set your iOS notification environment using the expo-notifications config plugin ([what's a config plugin?](https://docs.expo.dev/config-plugins/introduction)). To setup, just add the config plugin to the plugins array of your `app.json` or `app.config.js` as shown below, then rebuild the app.
130
130
 
131
131
  ```json
132
132
  {
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '0.22.0'
6
+ version = '0.24.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -53,13 +53,16 @@ afterEvaluate {
53
53
  android {
54
54
  compileSdkVersion safeExtGet("compileSdkVersion", 33)
55
55
 
56
- compileOptions {
57
- sourceCompatibility JavaVersion.VERSION_11
58
- targetCompatibility JavaVersion.VERSION_11
59
- }
56
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
57
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
58
+ compileOptions {
59
+ sourceCompatibility JavaVersion.VERSION_11
60
+ targetCompatibility JavaVersion.VERSION_11
61
+ }
60
62
 
61
- kotlinOptions {
62
- jvmTarget = JavaVersion.VERSION_11.majorVersion
63
+ kotlinOptions {
64
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
65
+ }
63
66
  }
64
67
 
65
68
  namespace "expo.modules.notifications"
@@ -67,7 +70,7 @@ android {
67
70
  minSdkVersion safeExtGet("minSdkVersion", 21)
68
71
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
72
  versionCode 21
70
- versionName '0.22.0'
73
+ versionName '0.24.0'
71
74
  }
72
75
 
73
76
  lintOptions {
@@ -78,6 +81,9 @@ android {
78
81
  withSourcesJar()
79
82
  }
80
83
  }
84
+ buildFeatures {
85
+ buildConfig true
86
+ }
81
87
  }
82
88
 
83
89
  dependencies {
@@ -11,7 +11,6 @@ import java.util.Arrays;
11
11
  import java.util.List;
12
12
 
13
13
  import expo.modules.notifications.badge.BadgeModule;
14
- import expo.modules.notifications.badge.ExpoBadgeManager;
15
14
  import expo.modules.notifications.serverregistration.ServerRegistrationModule;
16
15
  import expo.modules.notifications.notifications.NotificationManager;
17
16
  import expo.modules.notifications.notifications.background.ExpoBackgroundNotificationTasksModule;
@@ -51,8 +50,7 @@ public class NotificationsPackage extends BasePackage {
51
50
  public List<SingletonModule> createSingletonModules(Context context) {
52
51
  return Arrays.asList(
53
52
  new PushTokenManager(),
54
- new NotificationManager(),
55
- new ExpoBadgeManager(context)
53
+ new NotificationManager()
56
54
  );
57
55
  }
58
56
 
@@ -0,0 +1,37 @@
1
+ package expo.modules.notifications.badge
2
+
3
+ import android.content.Context
4
+ import android.util.Log
5
+ import expo.modules.core.ExportedModule
6
+ import expo.modules.core.Promise
7
+ import expo.modules.core.interfaces.ExpoMethod
8
+ import me.leolin.shortcutbadger.ShortcutBadgeException
9
+ import me.leolin.shortcutbadger.ShortcutBadger
10
+
11
+ class BadgeModule(context: Context) : ExportedModule(context) {
12
+ override fun getName(): String = "ExpoBadgeModule"
13
+
14
+ @ExpoMethod
15
+ fun getBadgeCountAsync(promise: Promise) {
16
+ promise.resolve(badgeCount)
17
+ }
18
+
19
+ @ExpoMethod
20
+ fun setBadgeCountAsync(badgeCount: Int, promise: Promise) {
21
+ try {
22
+ ShortcutBadger.applyCountOrThrow(context.applicationContext, badgeCount)
23
+ BadgeModule.badgeCount = badgeCount
24
+ promise.resolve(true)
25
+ } catch (e: ShortcutBadgeException) {
26
+ Log.d("expo-notifications", "Could not have set badge count: ${e.message}", e)
27
+ e.printStackTrace()
28
+ promise.resolve(false)
29
+ }
30
+ }
31
+
32
+ companion object {
33
+ var badgeCount = 0
34
+ get() = synchronized(this) { field }
35
+ set(value) = synchronized(this) { field = value }
36
+ }
37
+ }
@@ -4,7 +4,7 @@ import { NotificationPermissionsRequest, NotificationPermissionsStatus } from '.
4
4
  * It lets you verify whether the app is currently allowed to display alerts, play sounds, etc.
5
5
  * There is no user-facing effect of calling this.
6
6
  * @return It returns a `Promise` resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
7
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
7
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
8
8
  * @example Check if the app is allowed to send any type of notifications (interrupting and non-interrupting–provisional on iOS).
9
9
  * ```ts
10
10
  * import * as Notifications from 'expo-notifications';
@@ -24,7 +24,7 @@ export declare function getPermissionsAsync(): Promise<NotificationPermissionsSt
24
24
  * setting badge count and playing sounds**.
25
25
  * @param permissions An object representing configuration for the request scope.
26
26
  * @return It returns a Promise resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
27
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
27
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
28
28
  * @example Prompts the user to allow the app to show alerts, play sounds, set badge count and let Siri read out messages through AirPods.
29
29
  * ```ts
30
30
  * import * as Notifications from 'expo-notifications';
@@ -5,7 +5,7 @@ import NotificationPermissionsModule from './NotificationPermissionsModule';
5
5
  * It lets you verify whether the app is currently allowed to display alerts, play sounds, etc.
6
6
  * There is no user-facing effect of calling this.
7
7
  * @return It returns a `Promise` resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
8
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
8
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
9
9
  * @example Check if the app is allowed to send any type of notifications (interrupting and non-interrupting–provisional on iOS).
10
10
  * ```ts
11
11
  * import * as Notifications from 'expo-notifications';
@@ -30,7 +30,7 @@ export async function getPermissionsAsync() {
30
30
  * setting badge count and playing sounds**.
31
31
  * @param permissions An object representing configuration for the request scope.
32
32
  * @return It returns a Promise resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
33
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
33
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
34
34
  * @example Prompts the user to allow the app to show alerts, play sounds, set badge count and let Siri read out messages through AirPods.
35
35
  * ```ts
36
36
  * import * as Notifications from 'expo-notifications';
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationPermissions.js","sourceRoot":"","sources":["../src/NotificationPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxF,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,CAAC,6BAA6B,CAAC,mBAAmB,EAAE;QACtD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;KACvE;IAED,OAAO,MAAM,6BAA6B,CAAC,mBAAmB,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAA4C;IACxF,IAAI,CAAC,6BAA6B,CAAC,uBAAuB,EAAE;QAC1D,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;KAC3E;IAED,MAAM,oBAAoB,GAAG,WAAW,IAAI;QAC1C,GAAG,EAAE;YACH,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;SACjB;KACF,CAAC;IACF,MAAM,4BAA4B,GAAG,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,OAAO,MAAM,6BAA6B,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC;AACnG,CAAC;AAED,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAGhD;IACA,aAAa,EAAE,uBAAuB;IACtC,SAAS,EAAE,mBAAmB;CAC/B,CAAC,CAAC","sourcesContent":["import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport {\n NotificationPermissionsRequest,\n NotificationPermissionsStatus,\n} from './NotificationPermissions.types';\nimport NotificationPermissionsModule from './NotificationPermissionsModule';\n\n/**\n * Calling this function checks current permissions settings related to notifications.\n * It lets you verify whether the app is currently allowed to display alerts, play sounds, etc.\n * There is no user-facing effect of calling this.\n * @return It returns a `Promise` resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).\n * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).\n * @example Check if the app is allowed to send any type of notifications (interrupting and non-interrupting–provisional on iOS).\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export async function allowsNotificationsAsync() {\n * const settings = await Notifications.getPermissionsAsync();\n * return (\n * settings.granted || settings.ios?.status === Notifications.IosAuthorizationStatus.PROVISIONAL\n * );\n * }\n * ```\n * @header permissions\n */\nexport async function getPermissionsAsync() {\n if (!NotificationPermissionsModule.getPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'getPermissionsAsync');\n }\n\n return await NotificationPermissionsModule.getPermissionsAsync();\n}\n\n/**\n * Prompts the user for notification permissions according to request. **Request defaults to asking the user to allow displaying alerts,\n * setting badge count and playing sounds**.\n * @param permissions An object representing configuration for the request scope.\n * @return It returns a Promise resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).\n * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).\n * @example Prompts the user to allow the app to show alerts, play sounds, set badge count and let Siri read out messages through AirPods.\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export function requestPermissionsAsync() {\n * return await Notifications.requestPermissionsAsync({\n * ios: {\n * allowAlert: true,\n * allowBadge: true,\n * allowSound: true,\n * allowAnnouncements: true,\n * },\n * });\n * }\n * ```\n * @header permissions\n */\nexport async function requestPermissionsAsync(permissions?: NotificationPermissionsRequest) {\n if (!NotificationPermissionsModule.requestPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'requestPermissionsAsync');\n }\n\n const requestedPermissions = permissions ?? {\n ios: {\n allowAlert: true,\n allowBadge: true,\n allowSound: true,\n },\n };\n const requestedPlatformPermissions = requestedPermissions[Platform.OS];\n return await NotificationPermissionsModule.requestPermissionsAsync(requestedPlatformPermissions);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to send and receive push notifications.\n * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.\n * @example\n * ```ts\n * const [permissionResponse, requestPermission] = Notifications.usePermissions();\n * ```\n * @header permission\n */\nexport const usePermissions = createPermissionHook<\n NotificationPermissionsStatus,\n NotificationPermissionsRequest\n>({\n requestMethod: requestPermissionsAsync,\n getMethod: getPermissionsAsync,\n});\n"]}
1
+ {"version":3,"file":"NotificationPermissions.js","sourceRoot":"","sources":["../src/NotificationPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxF,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,CAAC,6BAA6B,CAAC,mBAAmB,EAAE;QACtD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;KACvE;IAED,OAAO,MAAM,6BAA6B,CAAC,mBAAmB,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAA4C;IACxF,IAAI,CAAC,6BAA6B,CAAC,uBAAuB,EAAE;QAC1D,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;KAC3E;IAED,MAAM,oBAAoB,GAAG,WAAW,IAAI;QAC1C,GAAG,EAAE;YACH,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;SACjB;KACF,CAAC;IACF,MAAM,4BAA4B,GAAG,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,OAAO,MAAM,6BAA6B,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC;AACnG,CAAC;AAED,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAGhD;IACA,aAAa,EAAE,uBAAuB;IACtC,SAAS,EAAE,mBAAmB;CAC/B,CAAC,CAAC","sourcesContent":["import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport {\n NotificationPermissionsRequest,\n NotificationPermissionsStatus,\n} from './NotificationPermissions.types';\nimport NotificationPermissionsModule from './NotificationPermissionsModule';\n\n/**\n * Calling this function checks current permissions settings related to notifications.\n * It lets you verify whether the app is currently allowed to display alerts, play sounds, etc.\n * There is no user-facing effect of calling this.\n * @return It returns a `Promise` resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).\n * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).\n * @example Check if the app is allowed to send any type of notifications (interrupting and non-interrupting–provisional on iOS).\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export async function allowsNotificationsAsync() {\n * const settings = await Notifications.getPermissionsAsync();\n * return (\n * settings.granted || settings.ios?.status === Notifications.IosAuthorizationStatus.PROVISIONAL\n * );\n * }\n * ```\n * @header permissions\n */\nexport async function getPermissionsAsync() {\n if (!NotificationPermissionsModule.getPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'getPermissionsAsync');\n }\n\n return await NotificationPermissionsModule.getPermissionsAsync();\n}\n\n/**\n * Prompts the user for notification permissions according to request. **Request defaults to asking the user to allow displaying alerts,\n * setting badge count and playing sounds**.\n * @param permissions An object representing configuration for the request scope.\n * @return It returns a Promise resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).\n * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).\n * @example Prompts the user to allow the app to show alerts, play sounds, set badge count and let Siri read out messages through AirPods.\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export function requestPermissionsAsync() {\n * return await Notifications.requestPermissionsAsync({\n * ios: {\n * allowAlert: true,\n * allowBadge: true,\n * allowSound: true,\n * allowAnnouncements: true,\n * },\n * });\n * }\n * ```\n * @header permissions\n */\nexport async function requestPermissionsAsync(permissions?: NotificationPermissionsRequest) {\n if (!NotificationPermissionsModule.requestPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'requestPermissionsAsync');\n }\n\n const requestedPermissions = permissions ?? {\n ios: {\n allowAlert: true,\n allowBadge: true,\n allowSound: true,\n },\n };\n const requestedPlatformPermissions = requestedPermissions[Platform.OS];\n return await NotificationPermissionsModule.requestPermissionsAsync(requestedPlatformPermissions);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to send and receive push notifications.\n * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.\n * @example\n * ```ts\n * const [permissionResponse, requestPermission] = Notifications.usePermissions();\n * ```\n * @header permission\n */\nexport const usePermissions = createPermissionHook<\n NotificationPermissionsStatus,\n NotificationPermissionsRequest\n>({\n requestMethod: requestPermissionsAsync,\n getMethod: getPermissionsAsync,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ServerRegistrationModule.web.d.ts","sourceRoot":"","sources":["../src/ServerRegistrationModule.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;;AAW5E,wBAoC8B"}
1
+ {"version":3,"file":"ServerRegistrationModule.web.d.ts","sourceRoot":"","sources":["../src/ServerRegistrationModule.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;;AAW5E,wBA0C8B"}
@@ -1,9 +1,9 @@
1
- import { CodedError, uuidv4 } from 'expo-modules-core';
1
+ import { CodedError, uuid } from 'expo-modules-core';
2
2
  const INSTALLATION_ID_KEY = 'EXPO_NOTIFICATIONS_INSTALLATION_ID';
3
3
  const REGISTRATION_INFO_KEY = 'EXPO_NOTIFICATIONS_REGISTRATION_INFO';
4
4
  // Lazy fallback installationId per session initializer
5
5
  let getFallbackInstallationId = () => {
6
- const sessionInstallationId = uuidv4();
6
+ const sessionInstallationId = uuid.v4();
7
7
  getFallbackInstallationId = () => sessionInstallationId;
8
8
  };
9
9
  export default {
@@ -12,7 +12,7 @@ export default {
12
12
  try {
13
13
  installationId = localStorage.getItem(INSTALLATION_ID_KEY);
14
14
  if (!installationId || typeof installationId !== 'string') {
15
- installationId = uuidv4();
15
+ installationId = uuid.v4();
16
16
  localStorage.setItem(INSTALLATION_ID_KEY, installationId);
17
17
  }
18
18
  }
@@ -22,9 +22,15 @@ export default {
22
22
  return installationId;
23
23
  },
24
24
  getRegistrationInfoAsync: async () => {
25
+ if (typeof localStorage === 'undefined') {
26
+ return null;
27
+ }
25
28
  return localStorage.getItem(REGISTRATION_INFO_KEY);
26
29
  },
27
30
  setRegistrationInfoAsync: async (registrationInfo) => {
31
+ if (typeof localStorage === 'undefined') {
32
+ return;
33
+ }
28
34
  try {
29
35
  if (registrationInfo) {
30
36
  localStorage.setItem(REGISTRATION_INFO_KEY, registrationInfo);
@@ -1 +1 @@
1
- {"version":3,"file":"ServerRegistrationModule.web.js","sourceRoot":"","sources":["../src/ServerRegistrationModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIvD,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AACjE,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AAErE,uDAAuD;AACvD,IAAI,yBAAyB,GAAG,GAAG,EAAE;IACnC,MAAM,qBAAqB,GAAG,MAAM,EAAE,CAAC;IACvC,yBAAyB,GAAG,GAAG,EAAE,CAAC,qBAAqB,CAAC;AAC1D,CAAC,CAAC;AAEF,eAAe;IACb,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACjC,IAAI,cAAc,CAAC;QAEnB,IAAI;YACF,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YAC3D,IAAI,CAAC,cAAc,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;gBACzD,cAAc,GAAG,MAAM,EAAE,CAAC;gBAC1B,YAAY,CAAC,OAAO,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;aAC3D;SACF;QAAC,MAAM;YACN,cAAc,GAAG,yBAAyB,EAAE,CAAC;SAC9C;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACnC,OAAO,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACrD,CAAC;IACD,wBAAwB,EAAE,KAAK,EAAE,gBAA+B,EAAE,EAAE;QAClE,IAAI;YACF,IAAI,gBAAgB,EAAE;gBACpB,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;aAC/D;iBAAM;gBACL,YAAY,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;aAChD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,UAAU,CAClB,iCAAiC,EACjC,2EAA2E,KAAK,EAAE,CACnF,CAAC;SACH;IACH,CAAC;IACD,uBAAuB;IACvB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;IACrB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;CACE,CAAC","sourcesContent":["import { CodedError, uuidv4 } from 'expo-modules-core';\n\nimport { ServerRegistrationModule } from './ServerRegistrationModule.types';\n\nconst INSTALLATION_ID_KEY = 'EXPO_NOTIFICATIONS_INSTALLATION_ID';\nconst REGISTRATION_INFO_KEY = 'EXPO_NOTIFICATIONS_REGISTRATION_INFO';\n\n// Lazy fallback installationId per session initializer\nlet getFallbackInstallationId = () => {\n const sessionInstallationId = uuidv4();\n getFallbackInstallationId = () => sessionInstallationId;\n};\n\nexport default {\n getInstallationIdAsync: async () => {\n let installationId;\n\n try {\n installationId = localStorage.getItem(INSTALLATION_ID_KEY);\n if (!installationId || typeof installationId !== 'string') {\n installationId = uuidv4();\n localStorage.setItem(INSTALLATION_ID_KEY, installationId);\n }\n } catch {\n installationId = getFallbackInstallationId();\n }\n\n return installationId;\n },\n getRegistrationInfoAsync: async () => {\n return localStorage.getItem(REGISTRATION_INFO_KEY);\n },\n setRegistrationInfoAsync: async (registrationInfo: string | null) => {\n try {\n if (registrationInfo) {\n localStorage.setItem(REGISTRATION_INFO_KEY, registrationInfo);\n } else {\n localStorage.removeItem(REGISTRATION_INFO_KEY);\n }\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_STORAGE_ERROR',\n `Could not modify localStorage to persist auto-registration information: ${error}`\n );\n }\n },\n // mock implementations\n addListener: () => {},\n removeListeners: () => {},\n} as ServerRegistrationModule;\n"]}
1
+ {"version":3,"file":"ServerRegistrationModule.web.js","sourceRoot":"","sources":["../src/ServerRegistrationModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIrD,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AACjE,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AAErE,uDAAuD;AACvD,IAAI,yBAAyB,GAAG,GAAG,EAAE;IACnC,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IACxC,yBAAyB,GAAG,GAAG,EAAE,CAAC,qBAAqB,CAAC;AAC1D,CAAC,CAAC;AAEF,eAAe;IACb,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACjC,IAAI,cAAc,CAAC;QAEnB,IAAI;YACF,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YAC3D,IAAI,CAAC,cAAc,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;gBACzD,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;gBAC3B,YAAY,CAAC,OAAO,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;aAC3D;SACF;QAAC,MAAM;YACN,cAAc,GAAG,yBAAyB,EAAE,CAAC;SAC9C;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACnC,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;QACD,OAAO,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACrD,CAAC;IACD,wBAAwB,EAAE,KAAK,EAAE,gBAA+B,EAAE,EAAE;QAClE,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;YACvC,OAAO;SACR;QACD,IAAI;YACF,IAAI,gBAAgB,EAAE;gBACpB,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;aAC/D;iBAAM;gBACL,YAAY,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;aAChD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,UAAU,CAClB,iCAAiC,EACjC,2EAA2E,KAAK,EAAE,CACnF,CAAC;SACH;IACH,CAAC;IACD,uBAAuB;IACvB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;IACrB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;CACE,CAAC","sourcesContent":["import { CodedError, uuid } from 'expo-modules-core';\n\nimport { ServerRegistrationModule } from './ServerRegistrationModule.types';\n\nconst INSTALLATION_ID_KEY = 'EXPO_NOTIFICATIONS_INSTALLATION_ID';\nconst REGISTRATION_INFO_KEY = 'EXPO_NOTIFICATIONS_REGISTRATION_INFO';\n\n// Lazy fallback installationId per session initializer\nlet getFallbackInstallationId = () => {\n const sessionInstallationId = uuid.v4();\n getFallbackInstallationId = () => sessionInstallationId;\n};\n\nexport default {\n getInstallationIdAsync: async () => {\n let installationId;\n\n try {\n installationId = localStorage.getItem(INSTALLATION_ID_KEY);\n if (!installationId || typeof installationId !== 'string') {\n installationId = uuid.v4();\n localStorage.setItem(INSTALLATION_ID_KEY, installationId);\n }\n } catch {\n installationId = getFallbackInstallationId();\n }\n\n return installationId;\n },\n getRegistrationInfoAsync: async () => {\n if (typeof localStorage === 'undefined') {\n return null;\n }\n return localStorage.getItem(REGISTRATION_INFO_KEY);\n },\n setRegistrationInfoAsync: async (registrationInfo: string | null) => {\n if (typeof localStorage === 'undefined') {\n return;\n }\n try {\n if (registrationInfo) {\n localStorage.setItem(REGISTRATION_INFO_KEY, registrationInfo);\n } else {\n localStorage.removeItem(REGISTRATION_INFO_KEY);\n }\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_STORAGE_ERROR',\n `Could not modify localStorage to persist auto-registration information: ${error}`\n );\n }\n },\n // mock implementations\n addListener: () => {},\n removeListeners: () => {},\n} as ServerRegistrationModule;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"presentNotificationAsync.d.ts","sourceRoot":"","sources":["../src/presentNotificationAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAIjE;;;;;;;GAOG;AACH,wBAA8B,wBAAwB,CACpD,OAAO,EAAE,wBAAwB,EACjC,UAAU,GAAE,MAAiB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAajB"}
1
+ {"version":3,"file":"presentNotificationAsync.d.ts","sourceRoot":"","sources":["../src/presentNotificationAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAIjE;;;;;;;GAOG;AACH,wBAA8B,wBAAwB,CACpD,OAAO,EAAE,wBAAwB,EACjC,UAAU,GAAE,MAAkB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAajB"}
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError, uuidv4 } from 'expo-modules-core';
1
+ import { UnavailabilityError, uuid } from 'expo-modules-core';
2
2
  import NotificationPresenter from './NotificationPresenterModule';
3
3
  let warningMessageShown = false;
4
4
  /**
@@ -9,7 +9,7 @@ let warningMessageShown = false;
9
9
  * @header schedule
10
10
  * @deprecated This method has been deprecated in favor of using an explicit `NotificationHandler` and the [`scheduleNotificationAsync`](#notificationsschedulenotificationasyncrequest) method. More information can be found in our [FYI document](https://expo.fyi/presenting-notifications-deprecated).
11
11
  */
12
- export default async function presentNotificationAsync(content, identifier = uuidv4()) {
12
+ export default async function presentNotificationAsync(content, identifier = uuid.v4()) {
13
13
  if (__DEV__ && !warningMessageShown) {
14
14
  console.warn('`presentNotificationAsync` has been deprecated in favor of using `scheduleNotificationAsync` + an explicit notification handler. Read more at https://expo.fyi/presenting-notifications-deprecated.');
15
15
  warningMessageShown = true;
@@ -1 +1 @@
1
- {"version":3,"file":"presentNotificationAsync.js","sourceRoot":"","sources":["../src/presentNotificationAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;AAGlE,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,wBAAwB,CACpD,OAAiC,EACjC,aAAqB,MAAM,EAAE;IAE7B,IAAI,OAAO,IAAI,CAAC,mBAAmB,EAAE;QACnC,OAAO,CAAC,IAAI,CACV,qMAAqM,CACtM,CAAC;QACF,mBAAmB,GAAG,IAAI,CAAC;KAC5B;IAED,IAAI,CAAC,qBAAqB,CAAC,wBAAwB,EAAE;QACnD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;KAC5E;IAED,OAAO,MAAM,qBAAqB,CAAC,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { UnavailabilityError, uuidv4 } from 'expo-modules-core';\n\nimport NotificationPresenter from './NotificationPresenterModule';\nimport { NotificationContentInput } from './Notifications.types';\n\nlet warningMessageShown = false;\n\n/**\n * Schedules a notification for immediate trigger.\n * @param content An object representing the notification content.\n * @param identifier\n * @return It returns a Promise resolving with the notification's identifier once the notification is successfully scheduled for immediate display.\n * @header schedule\n * @deprecated This method has been deprecated in favor of using an explicit `NotificationHandler` and the [`scheduleNotificationAsync`](#notificationsschedulenotificationasyncrequest) method. More information can be found in our [FYI document](https://expo.fyi/presenting-notifications-deprecated).\n */\nexport default async function presentNotificationAsync(\n content: NotificationContentInput,\n identifier: string = uuidv4()\n): Promise<string> {\n if (__DEV__ && !warningMessageShown) {\n console.warn(\n '`presentNotificationAsync` has been deprecated in favor of using `scheduleNotificationAsync` + an explicit notification handler. Read more at https://expo.fyi/presenting-notifications-deprecated.'\n );\n warningMessageShown = true;\n }\n\n if (!NotificationPresenter.presentNotificationAsync) {\n throw new UnavailabilityError('Notifications', 'presentNotificationAsync');\n }\n\n return await NotificationPresenter.presentNotificationAsync(identifier, content);\n}\n"]}
1
+ {"version":3,"file":"presentNotificationAsync.js","sourceRoot":"","sources":["../src/presentNotificationAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;AAGlE,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,wBAAwB,CACpD,OAAiC,EACjC,aAAqB,IAAI,CAAC,EAAE,EAAE;IAE9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,EAAE;QACnC,OAAO,CAAC,IAAI,CACV,qMAAqM,CACtM,CAAC;QACF,mBAAmB,GAAG,IAAI,CAAC;KAC5B;IAED,IAAI,CAAC,qBAAqB,CAAC,wBAAwB,EAAE;QACnD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;KAC5E;IAED,OAAO,MAAM,qBAAqB,CAAC,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { UnavailabilityError, uuid } from 'expo-modules-core';\n\nimport NotificationPresenter from './NotificationPresenterModule';\nimport { NotificationContentInput } from './Notifications.types';\n\nlet warningMessageShown = false;\n\n/**\n * Schedules a notification for immediate trigger.\n * @param content An object representing the notification content.\n * @param identifier\n * @return It returns a Promise resolving with the notification's identifier once the notification is successfully scheduled for immediate display.\n * @header schedule\n * @deprecated This method has been deprecated in favor of using an explicit `NotificationHandler` and the [`scheduleNotificationAsync`](#notificationsschedulenotificationasyncrequest) method. More information can be found in our [FYI document](https://expo.fyi/presenting-notifications-deprecated).\n */\nexport default async function presentNotificationAsync(\n content: NotificationContentInput,\n identifier: string = uuid.v4()\n): Promise<string> {\n if (__DEV__ && !warningMessageShown) {\n console.warn(\n '`presentNotificationAsync` has been deprecated in favor of using `scheduleNotificationAsync` + an explicit notification handler. Read more at https://expo.fyi/presenting-notifications-deprecated.'\n );\n warningMessageShown = true;\n }\n\n if (!NotificationPresenter.presentNotificationAsync) {\n throw new UnavailabilityError('Notifications', 'presentNotificationAsync');\n }\n\n return await NotificationPresenter.presentNotificationAsync(identifier, content);\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * When a notification is received while the app is backgrounded, using this function you can set a callback that will be run in response to that notification.
3
- * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](/task-manager#taskmanagerdefinetasktaskname-taskexecutor).
3
+ * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](./task-manager#taskmanagerdefinetasktaskname-taskexecutor).
4
4
  * Make sure you define it in the global scope.
5
5
  *
6
6
  * The callback function you define with `TaskManager.defineTask` will receive an object with the following fields:
7
- * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). [See here for details](#pushnotificationtrigger).
7
+ * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). See [`PushNotificationTrigger`](#pushnotificationtrigger) for details.
8
8
  * - `error`: The error (if any) that occurred during execution of the task.
9
9
  * - `executionInfo`: JSON object of additional info related to the task, including the `taskName`.
10
10
  * @param taskName The string you passed to `TaskManager.defineTask` as the `taskName` parameter.
@@ -2,11 +2,11 @@ import { UnavailabilityError } from 'expo-modules-core';
2
2
  import BackgroundNotificationTasksModule from './BackgroundNotificationTasksModule.native';
3
3
  /**
4
4
  * When a notification is received while the app is backgrounded, using this function you can set a callback that will be run in response to that notification.
5
- * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](/task-manager#taskmanagerdefinetasktaskname-taskexecutor).
5
+ * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](./task-manager#taskmanagerdefinetasktaskname-taskexecutor).
6
6
  * Make sure you define it in the global scope.
7
7
  *
8
8
  * The callback function you define with `TaskManager.defineTask` will receive an object with the following fields:
9
- * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). [See here for details](#pushnotificationtrigger).
9
+ * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). See [`PushNotificationTrigger`](#pushnotificationtrigger) for details.
10
10
  * - `error`: The error (if any) that occurred during execution of the task.
11
11
  * - `executionInfo`: JSON object of additional info related to the task, including the `taskName`.
12
12
  * @param taskName The string you passed to `TaskManager.defineTask` as the `taskName` parameter.
@@ -1 +1 @@
1
- {"version":3,"file":"registerTaskAsync.js","sourceRoot":"","sources":["../src/registerTaskAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,iCAAiC,MAAM,4CAA4C,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAgB;IAC9D,IAAI,CAAC,iCAAiC,CAAC,iBAAiB,EAAE;QACxD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;KACrE;IAED,OAAO,MAAM,iCAAiC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport BackgroundNotificationTasksModule from './BackgroundNotificationTasksModule.native';\n\n/**\n * When a notification is received while the app is backgrounded, using this function you can set a callback that will be run in response to that notification.\n * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](/task-manager#taskmanagerdefinetasktaskname-taskexecutor).\n * Make sure you define it in the global scope.\n *\n * The callback function you define with `TaskManager.defineTask` will receive an object with the following fields:\n * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). [See here for details](#pushnotificationtrigger).\n * - `error`: The error (if any) that occurred during execution of the task.\n * - `executionInfo`: JSON object of additional info related to the task, including the `taskName`.\n * @param taskName The string you passed to `TaskManager.defineTask` as the `taskName` parameter.\n *\n * @example\n * ```ts\n * import * as TaskManager from 'expo-task-manager';\n * import * as Notifications from 'expo-notifications';\n *\n * const BACKGROUND_NOTIFICATION_TASK = 'BACKGROUND-NOTIFICATION-TASK';\n *\n * TaskManager.defineTask(BACKGROUND_NOTIFICATION_TASK, ({ data, error, executionInfo }) => {\n * console.log('Received a notification in the background!');\n * // Do something with the notification data\n * });\n *\n * Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);\n * ```\n * @header inBackground\n */\nexport default async function registerTaskAsync(taskName: string): Promise<null> {\n if (!BackgroundNotificationTasksModule.registerTaskAsync) {\n throw new UnavailabilityError('Notifications', 'registerTaskAsync');\n }\n\n return await BackgroundNotificationTasksModule.registerTaskAsync(taskName);\n}\n"]}
1
+ {"version":3,"file":"registerTaskAsync.js","sourceRoot":"","sources":["../src/registerTaskAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,iCAAiC,MAAM,4CAA4C,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAgB;IAC9D,IAAI,CAAC,iCAAiC,CAAC,iBAAiB,EAAE;QACxD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;KACrE;IAED,OAAO,MAAM,iCAAiC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport BackgroundNotificationTasksModule from './BackgroundNotificationTasksModule.native';\n\n/**\n * When a notification is received while the app is backgrounded, using this function you can set a callback that will be run in response to that notification.\n * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](./task-manager#taskmanagerdefinetasktaskname-taskexecutor).\n * Make sure you define it in the global scope.\n *\n * The callback function you define with `TaskManager.defineTask` will receive an object with the following fields:\n * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). See [`PushNotificationTrigger`](#pushnotificationtrigger) for details.\n * - `error`: The error (if any) that occurred during execution of the task.\n * - `executionInfo`: JSON object of additional info related to the task, including the `taskName`.\n * @param taskName The string you passed to `TaskManager.defineTask` as the `taskName` parameter.\n *\n * @example\n * ```ts\n * import * as TaskManager from 'expo-task-manager';\n * import * as Notifications from 'expo-notifications';\n *\n * const BACKGROUND_NOTIFICATION_TASK = 'BACKGROUND-NOTIFICATION-TASK';\n *\n * TaskManager.defineTask(BACKGROUND_NOTIFICATION_TASK, ({ data, error, executionInfo }) => {\n * console.log('Received a notification in the background!');\n * // Do something with the notification data\n * });\n *\n * Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);\n * ```\n * @header inBackground\n */\nexport default async function registerTaskAsync(taskName: string): Promise<null> {\n if (!BackgroundNotificationTasksModule.registerTaskAsync) {\n throw new UnavailabilityError('Notifications', 'registerTaskAsync');\n }\n\n return await BackgroundNotificationTasksModule.registerTaskAsync(taskName);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Platform, UnavailabilityError, uuidv4 } from 'expo-modules-core';
1
+ import { Platform, UnavailabilityError, uuid } from 'expo-modules-core';
2
2
  import NotificationScheduler from './NotificationScheduler';
3
3
  /**
4
4
  * Schedules a notification to be triggered in the future.
@@ -59,7 +59,7 @@ export default async function scheduleNotificationAsync(request) {
59
59
  if (!NotificationScheduler.scheduleNotificationAsync) {
60
60
  throw new UnavailabilityError('Notifications', 'scheduleNotificationAsync');
61
61
  }
62
- return await NotificationScheduler.scheduleNotificationAsync(request.identifier ?? uuidv4(), request.content, parseTrigger(request.trigger));
62
+ return await NotificationScheduler.scheduleNotificationAsync(request.identifier ?? uuid.v4(), request.content, parseTrigger(request.trigger));
63
63
  }
64
64
  const DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS = [
65
65
  'hour',
@@ -1 +1 @@
1
- {"version":3,"file":"scheduleNotificationAsync.js","sourceRoot":"","sources":["../src/scheduleNotificationAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAe5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,yBAAyB,CACrD,OAAiC;IAEjC,IAAI,CAAC,qBAAqB,CAAC,yBAAyB,EAAE;QACpD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;KAC7E;IAED,OAAO,MAAM,qBAAqB,CAAC,yBAAyB,CAC1D,OAAO,CAAC,UAAU,IAAI,MAAM,EAAE,EAC9B,OAAO,CAAC,OAAO,EACf,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAC9B,CAAC;AACJ,CAAC;AAID,MAAM,sCAAsC,GAA0C;IACpF,MAAM;IACN,QAAQ;CACT,CAAC;AACF,MAAM,uCAAuC,GAA0C;IACrF,SAAS;IACT,MAAM;IACN,QAAQ;CACT,CAAC;AACF,MAAM,uCAAuC,GAA0C;IACrF,KAAK;IACL,OAAO;IACP,MAAM;IACN,QAAQ;CACT,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,iBAA2C;IAE3C,IAAI,iBAAiB,KAAK,IAAI,EAAE;QAC9B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACnC,MAAM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AC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,QAAgB,CAAC,EAAE,IAAa;IACnD,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import { Platform, UnavailabilityError, uuidv4 } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport { NotificationTriggerInput as NativeNotificationTriggerInput } from './NotificationScheduler.types';\nimport {\n NotificationRequestInput,\n NotificationTriggerInput,\n DailyTriggerInput,\n WeeklyTriggerInput,\n YearlyTriggerInput,\n CalendarTriggerInput,\n TimeIntervalTriggerInput,\n DateTriggerInput,\n ChannelAwareTriggerInput,\n SchedulableNotificationTriggerInput,\n} from './Notifications.types';\n\n/**\n * Schedules a notification to be triggered in the future.\n * > **Note:** Please note that this does not mean that the notification will be presented when it is triggered.\n * For the notification to be presented you have to set a notification handler with [`setNotificationHandler`](#notificationssetnotificationhandlerhandler)\n * that will return an appropriate notification behavior. For more information see the example below.\n * @param request An object describing the notification to be triggered.\n * @return Returns a Promise resolving to a string which is a notification identifier you can later use to cancel the notification or to identify an incoming notification.\n * @example\n * # Schedule the notification that will trigger once, in one minute from now\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: \"Time's up!\",\n * body: 'Change sides!',\n * },\n * trigger: {\n * seconds: 60,\n * },\n * });\n * ```\n *\n * # Schedule the notification that will trigger repeatedly, every 20 minutes\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: 'Remember to drink water!',\n * },\n * trigger: {\n * seconds: 60 * 20,\n * repeats: true,\n * },\n * });\n * ```\n *\n * # Schedule the notification that will trigger once, at the beginning of next hour\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * const trigger = new Date(Date.now() + 60 * 60 * 1000);\n * trigger.setMinutes(0);\n * trigger.setSeconds(0);\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: 'Happy new hour!',\n * },\n * trigger,\n * });\n * ```\n * @header schedule\n */\nexport default async function scheduleNotificationAsync(\n request: NotificationRequestInput\n): Promise<string> {\n if (!NotificationScheduler.scheduleNotificationAsync) {\n throw new UnavailabilityError('Notifications', 'scheduleNotificationAsync');\n }\n\n return await NotificationScheduler.scheduleNotificationAsync(\n request.identifier ?? uuidv4(),\n request.content,\n parseTrigger(request.trigger)\n );\n}\n\ntype ValidTriggerDateComponents = 'month' | 'day' | 'weekday' | 'hour' | 'minute';\n\nconst DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'hour',\n 'minute',\n];\nconst WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'weekday',\n 'hour',\n 'minute',\n];\nconst YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'day',\n 'month',\n 'hour',\n 'minute',\n];\n\nexport function parseTrigger(\n userFacingTrigger: NotificationTriggerInput\n): NativeNotificationTriggerInput {\n if (userFacingTrigger === null) {\n return null;\n }\n\n if (userFacingTrigger === undefined) {\n throw new TypeError(\n 'Encountered an `undefined` notification trigger. If you want to trigger the notification immediately, pass in an explicit `null` value.'\n );\n }\n\n if (isDateTrigger(userFacingTrigger)) {\n return parseDateTrigger(userFacingTrigger);\n } else if (isDailyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'daily',\n channelId: userFacingTrigger.channelId,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isWeeklyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'weekly',\n channelId: userFacingTrigger.channelId,\n weekday: userFacingTrigger.weekday,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isYearlyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'yearly',\n channelId: userFacingTrigger.channelId,\n day: userFacingTrigger.day,\n month: userFacingTrigger.month,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isSecondsPropertyMisusedInCalendarTriggerInput(userFacingTrigger)) {\n throw new TypeError(\n 'Could not have inferred the notification trigger type: if you want to use a time interval trigger, pass in only `seconds` with or without `repeats` property; if you want to use calendar-based trigger, pass in `second`.'\n );\n } else if ('seconds' in userFacingTrigger) {\n return {\n type: 'timeInterval',\n channelId: userFacingTrigger.channelId,\n seconds: userFacingTrigger.seconds,\n repeats: userFacingTrigger.repeats ?? false,\n };\n } else if (isCalendarTrigger(userFacingTrigger)) {\n const { repeats, ...calendarTrigger } = userFacingTrigger;\n return { type: 'calendar', value: calendarTrigger, repeats };\n } else {\n return Platform.select({\n default: null, // There's no notion of channels on platforms other than Android.\n android: { type: 'channel', channelId: userFacingTrigger.channelId },\n });\n }\n}\n\nfunction isCalendarTrigger(\n trigger: CalendarTriggerInput | ChannelAwareTriggerInput\n): trigger is CalendarTriggerInput {\n const { channelId, ...triggerWithoutChannelId } = trigger;\n return Object.keys(triggerWithoutChannelId).length > 0;\n}\n\nfunction isDateTrigger(\n trigger:\n | DateTriggerInput\n | WeeklyTriggerInput\n | DailyTriggerInput\n | CalendarTriggerInput\n | TimeIntervalTriggerInput\n): trigger is DateTriggerInput {\n return (\n trigger instanceof Date ||\n typeof trigger === 'number' ||\n (typeof trigger === 'object' && 'date' in trigger)\n );\n}\n\nfunction parseDateTrigger(trigger: DateTriggerInput): NativeNotificationTriggerInput {\n if (trigger instanceof Date || typeof trigger === 'number') {\n return { type: 'date', timestamp: toTimestamp(trigger) };\n }\n return { type: 'date', timestamp: toTimestamp(trigger.date), channelId: trigger.channelId };\n}\n\nfunction toTimestamp(date: number | Date) {\n if (date instanceof Date) {\n return date.getTime();\n }\n return date;\n}\n\nfunction isDailyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is DailyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as DailyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isWeeklyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is WeeklyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as WeeklyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isYearlyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is YearlyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as YearlyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isSecondsPropertyMisusedInCalendarTriggerInput(\n trigger: TimeIntervalTriggerInput | CalendarTriggerInput\n) {\n const { channelId, ...triggerWithoutChannelId } = trigger;\n return (\n // eg. { seconds: ..., repeats: ..., hour: ... }\n ('seconds' in triggerWithoutChannelId &&\n 'repeats' in triggerWithoutChannelId &&\n Object.keys(triggerWithoutChannelId).length > 2) ||\n // eg. { seconds: ..., hour: ... }\n ('seconds' in triggerWithoutChannelId &&\n !('repeats' in triggerWithoutChannelId) &&\n Object.keys(triggerWithoutChannelId).length > 1)\n );\n}\n\nfunction validateDateComponentsInTrigger(\n trigger: NonNullable<NotificationTriggerInput>,\n components: readonly ValidTriggerDateComponents[]\n) {\n const anyTriggerType = trigger as any;\n components.forEach((component) => {\n if (!(component in anyTriggerType)) {\n throw new TypeError(`The ${component} parameter needs to be present`);\n }\n if (typeof anyTriggerType[component] !== 'number') {\n throw new TypeError(`The ${component} parameter should be a number`);\n }\n switch (component) {\n case 'month': {\n const { month } = anyTriggerType;\n if (month < 0 || month > 11) {\n throw new RangeError(`The month parameter needs to be between 0 and 11. Found: ${month}`);\n }\n break;\n }\n case 'day': {\n const { day, month } = anyTriggerType;\n const daysInGivenMonth = daysInMonth(month);\n if (day < 1 || day > daysInGivenMonth) {\n throw new RangeError(\n `The day parameter for month ${month} must be between 1 and ${daysInGivenMonth}. Found: ${day}`\n );\n }\n break;\n }\n case 'weekday': {\n const { weekday } = anyTriggerType;\n if (weekday < 1 || weekday > 7) {\n throw new RangeError(\n `The weekday parameter needs to be between 1 and 7. Found: ${weekday}`\n );\n }\n break;\n }\n case 'hour': {\n const { hour } = anyTriggerType;\n if (hour < 0 || hour > 23) {\n throw new RangeError(`The hour parameter needs to be between 0 and 23. Found: ${hour}`);\n }\n break;\n }\n case 'minute': {\n const { minute } = anyTriggerType;\n if (minute < 0 || minute > 59) {\n throw new RangeError(\n `The minute parameter needs to be between 0 and 59. Found: ${minute}`\n );\n }\n break;\n }\n }\n });\n}\n\n/**\n * Determines the number of days in the given month (or January if omitted).\n * If year is specified, it will include leap year logic, else it will always assume a leap year\n */\nfunction daysInMonth(month: number = 0, year?: number) {\n return new Date(year ?? 2000, month + 1, 0).getDate();\n}\n"]}
1
+ {"version":3,"file":"scheduleNotificationAsync.js","sourceRoot":"","sources":["../src/scheduleNotificationAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAe5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,yBAAyB,CACrD,OAAiC;IAEjC,IAAI,CAAC,qBAAqB,CAAC,yBAAyB,EAAE;QACpD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;KAC7E;IAED,OAAO,MAAM,qBAAqB,CAAC,yBAAyB,CAC1D,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,EAAE,EAAE,EAC/B,OAAO,CAAC,OAAO,EACf,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAC9B,CAAC;AACJ,CAAC;AAID,MAAM,sCAAsC,GAA0C;IACpF,MAAM;IACN,QAAQ;CACT,CAAC;AACF,MAAM,uCAAuC,GAA0C;IACrF,SAAS;IACT,MAAM;IACN,QAAQ;CACT,CAAC;AACF,MAAM,uCAAuC,GAA0C;IACrF,KAAK;IACL,OAAO;IACP,MAAM;IACN,QAAQ;CACT,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,iBAA2C;IAE3C,IAAI,iBAAiB,KAAK,IAAI,EAAE;QAC9B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACnC,MAAM,IAAI,SAAS,CACjB,yIAAyI,CAC1I,CAAC;KACH;IAED,IAAI,aAAa,CAAC,iBAAiB,CAAC,EAAE;QACpC,OAAO,gBAAgB,CAAC,iBAAiB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,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import { Platform, UnavailabilityError, uuid } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport { NotificationTriggerInput as NativeNotificationTriggerInput } from './NotificationScheduler.types';\nimport {\n NotificationRequestInput,\n NotificationTriggerInput,\n DailyTriggerInput,\n WeeklyTriggerInput,\n YearlyTriggerInput,\n CalendarTriggerInput,\n TimeIntervalTriggerInput,\n DateTriggerInput,\n ChannelAwareTriggerInput,\n SchedulableNotificationTriggerInput,\n} from './Notifications.types';\n\n/**\n * Schedules a notification to be triggered in the future.\n * > **Note:** Please note that this does not mean that the notification will be presented when it is triggered.\n * For the notification to be presented you have to set a notification handler with [`setNotificationHandler`](#notificationssetnotificationhandlerhandler)\n * that will return an appropriate notification behavior. For more information see the example below.\n * @param request An object describing the notification to be triggered.\n * @return Returns a Promise resolving to a string which is a notification identifier you can later use to cancel the notification or to identify an incoming notification.\n * @example\n * # Schedule the notification that will trigger once, in one minute from now\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: \"Time's up!\",\n * body: 'Change sides!',\n * },\n * trigger: {\n * seconds: 60,\n * },\n * });\n * ```\n *\n * # Schedule the notification that will trigger repeatedly, every 20 minutes\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: 'Remember to drink water!',\n * },\n * trigger: {\n * seconds: 60 * 20,\n * repeats: true,\n * },\n * });\n * ```\n *\n * # Schedule the notification that will trigger once, at the beginning of next hour\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * const trigger = new Date(Date.now() + 60 * 60 * 1000);\n * trigger.setMinutes(0);\n * trigger.setSeconds(0);\n *\n * Notifications.scheduleNotificationAsync({\n * content: {\n * title: 'Happy new hour!',\n * },\n * trigger,\n * });\n * ```\n * @header schedule\n */\nexport default async function scheduleNotificationAsync(\n request: NotificationRequestInput\n): Promise<string> {\n if (!NotificationScheduler.scheduleNotificationAsync) {\n throw new UnavailabilityError('Notifications', 'scheduleNotificationAsync');\n }\n\n return await NotificationScheduler.scheduleNotificationAsync(\n request.identifier ?? uuid.v4(),\n request.content,\n parseTrigger(request.trigger)\n );\n}\n\ntype ValidTriggerDateComponents = 'month' | 'day' | 'weekday' | 'hour' | 'minute';\n\nconst DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'hour',\n 'minute',\n];\nconst WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'weekday',\n 'hour',\n 'minute',\n];\nconst YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS: readonly ValidTriggerDateComponents[] = [\n 'day',\n 'month',\n 'hour',\n 'minute',\n];\n\nexport function parseTrigger(\n userFacingTrigger: NotificationTriggerInput\n): NativeNotificationTriggerInput {\n if (userFacingTrigger === null) {\n return null;\n }\n\n if (userFacingTrigger === undefined) {\n throw new TypeError(\n 'Encountered an `undefined` notification trigger. If you want to trigger the notification immediately, pass in an explicit `null` value.'\n );\n }\n\n if (isDateTrigger(userFacingTrigger)) {\n return parseDateTrigger(userFacingTrigger);\n } else if (isDailyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'daily',\n channelId: userFacingTrigger.channelId,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isWeeklyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'weekly',\n channelId: userFacingTrigger.channelId,\n weekday: userFacingTrigger.weekday,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isYearlyTriggerInput(userFacingTrigger)) {\n validateDateComponentsInTrigger(userFacingTrigger, YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS);\n return {\n type: 'yearly',\n channelId: userFacingTrigger.channelId,\n day: userFacingTrigger.day,\n month: userFacingTrigger.month,\n hour: userFacingTrigger.hour,\n minute: userFacingTrigger.minute,\n };\n } else if (isSecondsPropertyMisusedInCalendarTriggerInput(userFacingTrigger)) {\n throw new TypeError(\n 'Could not have inferred the notification trigger type: if you want to use a time interval trigger, pass in only `seconds` with or without `repeats` property; if you want to use calendar-based trigger, pass in `second`.'\n );\n } else if ('seconds' in userFacingTrigger) {\n return {\n type: 'timeInterval',\n channelId: userFacingTrigger.channelId,\n seconds: userFacingTrigger.seconds,\n repeats: userFacingTrigger.repeats ?? false,\n };\n } else if (isCalendarTrigger(userFacingTrigger)) {\n const { repeats, ...calendarTrigger } = userFacingTrigger;\n return { type: 'calendar', value: calendarTrigger, repeats };\n } else {\n return Platform.select({\n default: null, // There's no notion of channels on platforms other than Android.\n android: { type: 'channel', channelId: userFacingTrigger.channelId },\n });\n }\n}\n\nfunction isCalendarTrigger(\n trigger: CalendarTriggerInput | ChannelAwareTriggerInput\n): trigger is CalendarTriggerInput {\n const { channelId, ...triggerWithoutChannelId } = trigger;\n return Object.keys(triggerWithoutChannelId).length > 0;\n}\n\nfunction isDateTrigger(\n trigger:\n | DateTriggerInput\n | WeeklyTriggerInput\n | DailyTriggerInput\n | CalendarTriggerInput\n | TimeIntervalTriggerInput\n): trigger is DateTriggerInput {\n return (\n trigger instanceof Date ||\n typeof trigger === 'number' ||\n (typeof trigger === 'object' && 'date' in trigger)\n );\n}\n\nfunction parseDateTrigger(trigger: DateTriggerInput): NativeNotificationTriggerInput {\n if (trigger instanceof Date || typeof trigger === 'number') {\n return { type: 'date', timestamp: toTimestamp(trigger) };\n }\n return { type: 'date', timestamp: toTimestamp(trigger.date), channelId: trigger.channelId };\n}\n\nfunction toTimestamp(date: number | Date) {\n if (date instanceof Date) {\n return date.getTime();\n }\n return date;\n}\n\nfunction isDailyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is DailyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as DailyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n DAILY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isWeeklyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is WeeklyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as WeeklyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n WEEKLY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isYearlyTriggerInput(\n trigger: SchedulableNotificationTriggerInput\n): trigger is YearlyTriggerInput {\n if (typeof trigger !== 'object') return false;\n const { channelId, ...triggerWithoutChannelId } = trigger as YearlyTriggerInput;\n return (\n Object.keys(triggerWithoutChannelId).length ===\n YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS.length + 1 &&\n YEARLY_TRIGGER_EXPECTED_DATE_COMPONENTS.every(\n (component) => component in triggerWithoutChannelId\n ) &&\n 'repeats' in triggerWithoutChannelId &&\n triggerWithoutChannelId.repeats === true\n );\n}\n\nfunction isSecondsPropertyMisusedInCalendarTriggerInput(\n trigger: TimeIntervalTriggerInput | CalendarTriggerInput\n) {\n const { channelId, ...triggerWithoutChannelId } = trigger;\n return (\n // eg. { seconds: ..., repeats: ..., hour: ... }\n ('seconds' in triggerWithoutChannelId &&\n 'repeats' in triggerWithoutChannelId &&\n Object.keys(triggerWithoutChannelId).length > 2) ||\n // eg. { seconds: ..., hour: ... }\n ('seconds' in triggerWithoutChannelId &&\n !('repeats' in triggerWithoutChannelId) &&\n Object.keys(triggerWithoutChannelId).length > 1)\n );\n}\n\nfunction validateDateComponentsInTrigger(\n trigger: NonNullable<NotificationTriggerInput>,\n components: readonly ValidTriggerDateComponents[]\n) {\n const anyTriggerType = trigger as any;\n components.forEach((component) => {\n if (!(component in anyTriggerType)) {\n throw new TypeError(`The ${component} parameter needs to be present`);\n }\n if (typeof anyTriggerType[component] !== 'number') {\n throw new TypeError(`The ${component} parameter should be a number`);\n }\n switch (component) {\n case 'month': {\n const { month } = anyTriggerType;\n if (month < 0 || month > 11) {\n throw new RangeError(`The month parameter needs to be between 0 and 11. Found: ${month}`);\n }\n break;\n }\n case 'day': {\n const { day, month } = anyTriggerType;\n const daysInGivenMonth = daysInMonth(month);\n if (day < 1 || day > daysInGivenMonth) {\n throw new RangeError(\n `The day parameter for month ${month} must be between 1 and ${daysInGivenMonth}. Found: ${day}`\n );\n }\n break;\n }\n case 'weekday': {\n const { weekday } = anyTriggerType;\n if (weekday < 1 || weekday > 7) {\n throw new RangeError(\n `The weekday parameter needs to be between 1 and 7. Found: ${weekday}`\n );\n }\n break;\n }\n case 'hour': {\n const { hour } = anyTriggerType;\n if (hour < 0 || hour > 23) {\n throw new RangeError(`The hour parameter needs to be between 0 and 23. Found: ${hour}`);\n }\n break;\n }\n case 'minute': {\n const { minute } = anyTriggerType;\n if (minute < 0 || minute > 59) {\n throw new RangeError(\n `The minute parameter needs to be between 0 and 59. Found: ${minute}`\n );\n }\n break;\n }\n }\n });\n}\n\n/**\n * Determines the number of days in the given month (or January if omitted).\n * If year is specified, it will include leap year logic, else it will always assume a leap year\n */\nfunction daysInMonth(month: number = 0, year?: number) {\n return new Date(year ?? 2000, month + 1, 0).getDate();\n}\n"]}
@@ -10,7 +10,7 @@ import { NotificationChannel, NotificationChannelInput } from './NotificationCha
10
10
  * the custom notification sound has to be set on the notification (through the [`NotificationContentInput`](#notificationcontentinput)),
11
11
  * and for the custom sound to play on Android versions **above** 8.0, the relevant notification channel must have the custom sound configured
12
12
  * (through the [`NotificationChannelInput`](#notificationchannelinput)). For more information,
13
- * see ["Setting custom notification sounds on Android"](#setting-custom-notification-sounds-on-android).
13
+ * see [Set custom notification sounds on Android](#set-custom-notification-sounds).
14
14
  * @param channelId The channel identifier.
15
15
  * @param channel Object representing the channel's configuration.
16
16
  * @return A Promise which resolving to the object (of type [`NotificationChannel`](#notificationchannel)) describing the modified channel
@@ -9,7 +9,7 @@
9
9
  * the custom notification sound has to be set on the notification (through the [`NotificationContentInput`](#notificationcontentinput)),
10
10
  * and for the custom sound to play on Android versions **above** 8.0, the relevant notification channel must have the custom sound configured
11
11
  * (through the [`NotificationChannelInput`](#notificationchannelinput)). For more information,
12
- * see ["Setting custom notification sounds on Android"](#setting-custom-notification-sounds-on-android).
12
+ * see [Set custom notification sounds on Android](#set-custom-notification-sounds).
13
13
  * @param channelId The channel identifier.
14
14
  * @param channel Object representing the channel's configuration.
15
15
  * @return A Promise which resolving to the object (of type [`NotificationChannel`](#notificationchannel)) describing the modified channel
@@ -1 +1 @@
1
- {"version":3,"file":"setNotificationChannelAsync.js","sourceRoot":"","sources":["../src/setNotificationChannelAsync.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,2BAA2B,CACvD,SAAiB,EACjB,OAAiC;IAEjC,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { NotificationChannel, NotificationChannelInput } from './NotificationChannelManager.types';\n\n/**\n * Assigns the channel configuration to a channel of a specified name (creating it if need be).\n * This method lets you assign given notification channel to a notification channel group.\n *\n * > **Note:** For some settings to be applied on all Android versions, it may be necessary to duplicate the configuration across both\n * > a single notification and its respective notification channel.\n *\n * For example, for a notification to play a custom sound on Android versions **below** 8.0,\n * the custom notification sound has to be set on the notification (through the [`NotificationContentInput`](#notificationcontentinput)),\n * and for the custom sound to play on Android versions **above** 8.0, the relevant notification channel must have the custom sound configured\n * (through the [`NotificationChannelInput`](#notificationchannelinput)). For more information,\n * see [\"Setting custom notification sounds on Android\"](#setting-custom-notification-sounds-on-android).\n * @param channelId The channel identifier.\n * @param channel Object representing the channel's configuration.\n * @return A Promise which resolving to the object (of type [`NotificationChannel`](#notificationchannel)) describing the modified channel\n * or to `null` if the platform does not support notification channels.\n * @platform android\n * @header channels\n */\nexport default async function setNotificationChannelAsync(\n channelId: string,\n channel: NotificationChannelInput\n): Promise<NotificationChannel | null> {\n console.debug('Notification channels feature is only supported on Android.');\n return null;\n}\n"]}
1
+ {"version":3,"file":"setNotificationChannelAsync.js","sourceRoot":"","sources":["../src/setNotificationChannelAsync.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,2BAA2B,CACvD,SAAiB,EACjB,OAAiC;IAEjC,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { NotificationChannel, NotificationChannelInput } from './NotificationChannelManager.types';\n\n/**\n * Assigns the channel configuration to a channel of a specified name (creating it if need be).\n * This method lets you assign given notification channel to a notification channel group.\n *\n * > **Note:** For some settings to be applied on all Android versions, it may be necessary to duplicate the configuration across both\n * > a single notification and its respective notification channel.\n *\n * For example, for a notification to play a custom sound on Android versions **below** 8.0,\n * the custom notification sound has to be set on the notification (through the [`NotificationContentInput`](#notificationcontentinput)),\n * and for the custom sound to play on Android versions **above** 8.0, the relevant notification channel must have the custom sound configured\n * (through the [`NotificationChannelInput`](#notificationchannelinput)). For more information,\n * see [Set custom notification sounds on Android](#set-custom-notification-sounds).\n * @param channelId The channel identifier.\n * @param channel Object representing the channel's configuration.\n * @return A Promise which resolving to the object (of type [`NotificationChannel`](#notificationchannel)) describing the modified channel\n * or to `null` if the platform does not support notification channels.\n * @platform android\n * @header channels\n */\nexport default async function setNotificationChannelAsync(\n channelId: string,\n channel: NotificationChannelInput\n): Promise<NotificationChannel | null> {\n console.debug('Notification channels feature is only supported on Android.');\n return null;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-notifications",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Notifications module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "abort-controller": "^3.0.0",
43
43
  "assert": "^2.0.0",
44
44
  "badgin": "^1.1.5",
45
- "expo-application": "~5.3.0",
46
- "expo-constants": "~14.5.0",
45
+ "expo-application": "~5.5.0",
46
+ "expo-constants": "~15.1.0",
47
47
  "fs-extra": "^9.1.0",
48
48
  "uuid": "^3.4.0"
49
49
  },
@@ -57,5 +57,5 @@
57
57
  "peerDependencies": {
58
58
  "expo": "*"
59
59
  },
60
- "gitHead": "2240630a92eb79a4e4bf73e1439916c394876478"
60
+ "gitHead": "ee2c866ba3c7fbc35ff2a3e896041cf15d3bd7c5"
61
61
  }
@@ -11,7 +11,7 @@ import NotificationPermissionsModule from './NotificationPermissionsModule';
11
11
  * It lets you verify whether the app is currently allowed to display alerts, play sounds, etc.
12
12
  * There is no user-facing effect of calling this.
13
13
  * @return It returns a `Promise` resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
14
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
14
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
15
15
  * @example Check if the app is allowed to send any type of notifications (interrupting and non-interrupting–provisional on iOS).
16
16
  * ```ts
17
17
  * import * as Notifications from 'expo-notifications';
@@ -38,7 +38,7 @@ export async function getPermissionsAsync() {
38
38
  * setting badge count and playing sounds**.
39
39
  * @param permissions An object representing configuration for the request scope.
40
40
  * @return It returns a Promise resolving to an object represents permission settings ([`NotificationPermissionsStatus`](#notificationpermissionsstatus)).
41
- * On iOS, make sure you [properly interpret the permissions response](#interpreting-the-ios-permissions-response).
41
+ * On iOS, make sure you [properly interpret the permissions response](#interpret-the-ios-permissions-response).
42
42
  * @example Prompts the user to allow the app to show alerts, play sounds, set badge count and let Siri read out messages through AirPods.
43
43
  * ```ts
44
44
  * import * as Notifications from 'expo-notifications';
@@ -1,4 +1,4 @@
1
- import { CodedError, uuidv4 } from 'expo-modules-core';
1
+ import { CodedError, uuid } from 'expo-modules-core';
2
2
 
3
3
  import { ServerRegistrationModule } from './ServerRegistrationModule.types';
4
4
 
@@ -7,7 +7,7 @@ const REGISTRATION_INFO_KEY = 'EXPO_NOTIFICATIONS_REGISTRATION_INFO';
7
7
 
8
8
  // Lazy fallback installationId per session initializer
9
9
  let getFallbackInstallationId = () => {
10
- const sessionInstallationId = uuidv4();
10
+ const sessionInstallationId = uuid.v4();
11
11
  getFallbackInstallationId = () => sessionInstallationId;
12
12
  };
13
13
 
@@ -18,7 +18,7 @@ export default {
18
18
  try {
19
19
  installationId = localStorage.getItem(INSTALLATION_ID_KEY);
20
20
  if (!installationId || typeof installationId !== 'string') {
21
- installationId = uuidv4();
21
+ installationId = uuid.v4();
22
22
  localStorage.setItem(INSTALLATION_ID_KEY, installationId);
23
23
  }
24
24
  } catch {
@@ -28,9 +28,15 @@ export default {
28
28
  return installationId;
29
29
  },
30
30
  getRegistrationInfoAsync: async () => {
31
+ if (typeof localStorage === 'undefined') {
32
+ return null;
33
+ }
31
34
  return localStorage.getItem(REGISTRATION_INFO_KEY);
32
35
  },
33
36
  setRegistrationInfoAsync: async (registrationInfo: string | null) => {
37
+ if (typeof localStorage === 'undefined') {
38
+ return;
39
+ }
34
40
  try {
35
41
  if (registrationInfo) {
36
42
  localStorage.setItem(REGISTRATION_INFO_KEY, registrationInfo);
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError, uuidv4 } from 'expo-modules-core';
1
+ import { UnavailabilityError, uuid } from 'expo-modules-core';
2
2
 
3
3
  import NotificationPresenter from './NotificationPresenterModule';
4
4
  import { NotificationContentInput } from './Notifications.types';
@@ -15,7 +15,7 @@ let warningMessageShown = false;
15
15
  */
16
16
  export default async function presentNotificationAsync(
17
17
  content: NotificationContentInput,
18
- identifier: string = uuidv4()
18
+ identifier: string = uuid.v4()
19
19
  ): Promise<string> {
20
20
  if (__DEV__ && !warningMessageShown) {
21
21
  console.warn(
@@ -4,11 +4,11 @@ import BackgroundNotificationTasksModule from './BackgroundNotificationTasksModu
4
4
 
5
5
  /**
6
6
  * When a notification is received while the app is backgrounded, using this function you can set a callback that will be run in response to that notification.
7
- * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](/task-manager#taskmanagerdefinetasktaskname-taskexecutor).
7
+ * Under the hood, this function is run using `expo-task-manager`. You **must** define the task first, with [`TaskManager.defineTask`](./task-manager#taskmanagerdefinetasktaskname-taskexecutor).
8
8
  * Make sure you define it in the global scope.
9
9
  *
10
10
  * The callback function you define with `TaskManager.defineTask` will receive an object with the following fields:
11
- * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). [See here for details](#pushnotificationtrigger).
11
+ * - `data`: The remote payload delivered by either FCM (Android) or APNs (iOS). See [`PushNotificationTrigger`](#pushnotificationtrigger) for details.
12
12
  * - `error`: The error (if any) that occurred during execution of the task.
13
13
  * - `executionInfo`: JSON object of additional info related to the task, including the `taskName`.
14
14
  * @param taskName The string you passed to `TaskManager.defineTask` as the `taskName` parameter.
@@ -1,4 +1,4 @@
1
- import { Platform, UnavailabilityError, uuidv4 } from 'expo-modules-core';
1
+ import { Platform, UnavailabilityError, uuid } from 'expo-modules-core';
2
2
 
3
3
  import NotificationScheduler from './NotificationScheduler';
4
4
  import { NotificationTriggerInput as NativeNotificationTriggerInput } from './NotificationScheduler.types';
@@ -78,7 +78,7 @@ export default async function scheduleNotificationAsync(
78
78
  }
79
79
 
80
80
  return await NotificationScheduler.scheduleNotificationAsync(
81
- request.identifier ?? uuidv4(),
81
+ request.identifier ?? uuid.v4(),
82
82
  request.content,
83
83
  parseTrigger(request.trigger)
84
84
  );
@@ -11,7 +11,7 @@ import { NotificationChannel, NotificationChannelInput } from './NotificationCha
11
11
  * the custom notification sound has to be set on the notification (through the [`NotificationContentInput`](#notificationcontentinput)),
12
12
  * and for the custom sound to play on Android versions **above** 8.0, the relevant notification channel must have the custom sound configured
13
13
  * (through the [`NotificationChannelInput`](#notificationchannelinput)). For more information,
14
- * see ["Setting custom notification sounds on Android"](#setting-custom-notification-sounds-on-android).
14
+ * see [Set custom notification sounds on Android](#set-custom-notification-sounds).
15
15
  * @param channelId The channel identifier.
16
16
  * @param channel Object representing the channel's configuration.
17
17
  * @return A Promise which resolving to the object (of type [`NotificationChannel`](#notificationchannel)) describing the modified channel
@@ -1,40 +0,0 @@
1
- package expo.modules.notifications.badge;
2
-
3
- import android.content.Context;
4
-
5
- import expo.modules.core.ExportedModule;
6
- import expo.modules.core.ModuleRegistry;
7
- import expo.modules.core.Promise;
8
- import expo.modules.core.interfaces.ExpoMethod;
9
-
10
- import expo.modules.notifications.badge.interfaces.BadgeManager;
11
-
12
- public class BadgeModule extends ExportedModule {
13
- private static final String EXPORTED_NAME = "ExpoBadgeModule";
14
-
15
- private BadgeManager mBadgeManager;
16
-
17
- public BadgeModule(Context context) {
18
- super(context);
19
- }
20
-
21
- @Override
22
- public String getName() {
23
- return EXPORTED_NAME;
24
- }
25
-
26
- @Override
27
- public void onCreate(ModuleRegistry moduleRegistry) {
28
- mBadgeManager = moduleRegistry.getSingletonModule("BadgeManager", BadgeManager.class);
29
- }
30
-
31
- @ExpoMethod
32
- public void getBadgeCountAsync(Promise promise) {
33
- promise.resolve(mBadgeManager.getBadgeCount());
34
- }
35
-
36
- @ExpoMethod
37
- public void setBadgeCountAsync(int badgeCount, Promise promise) {
38
- promise.resolve(mBadgeManager.setBadgeCount(badgeCount));
39
- }
40
- }
@@ -1,44 +0,0 @@
1
- package expo.modules.notifications.badge;
2
-
3
- import android.content.Context;
4
- import android.util.Log;
5
-
6
- import expo.modules.core.interfaces.SingletonModule;
7
-
8
- import expo.modules.notifications.badge.interfaces.BadgeManager;
9
- import me.leolin.shortcutbadger.ShortcutBadgeException;
10
- import me.leolin.shortcutbadger.ShortcutBadger;
11
-
12
- public class ExpoBadgeManager implements SingletonModule, BadgeManager {
13
- private static final String SINGLETON_NAME = "BadgeManager";
14
-
15
- private int mBadgeCount = 0;
16
- private Context mContext;
17
-
18
- public ExpoBadgeManager(Context context) {
19
- mContext = context;
20
- }
21
-
22
- @Override
23
- public String getName() {
24
- return SINGLETON_NAME;
25
- }
26
-
27
- @Override
28
- public int getBadgeCount() {
29
- return mBadgeCount;
30
- }
31
-
32
- @Override
33
- public boolean setBadgeCount(int badgeCount) {
34
- try {
35
- ShortcutBadger.applyCountOrThrow(mContext.getApplicationContext(), badgeCount);
36
- mBadgeCount = badgeCount;
37
- return true;
38
- } catch (ShortcutBadgeException e) {
39
- Log.d("expo-notifications", "Could not have set badge count: " + e.getMessage());
40
- e.printStackTrace();
41
- }
42
- return false;
43
- }
44
- }
@@ -1,7 +0,0 @@
1
- package expo.modules.notifications.badge.interfaces;
2
-
3
- public interface BadgeManager {
4
- int getBadgeCount();
5
-
6
- boolean setBadgeCount(int badgeCount);
7
- }