expo-notifications 1.0.0-canary-20250122-166c2cb → 1.0.0-canary-20250207-8bc5146

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.
package/CHANGELOG.md CHANGED
@@ -12,11 +12,16 @@
12
12
 
13
13
  ### 💡 Others
14
14
 
15
+ - Add better error when Firebase is not set up ([#34694](https://github.com/expo/expo/pull/34694) by [@vonovak](https://github.com/vonovak))
16
+ - [apple] Migrate remaining `expo-module.config.json` to unified platform syntax. ([#34445](https://github.com/expo/expo/pull/34445) by [@reichhartd](https://github.com/reichhartd))
17
+ - [iOS] Swift conversion 6: refactor Record classes. ([#34413](https://github.com/expo/expo/pull/34413) by [@douglowder](https://github.com/douglowder))
18
+
15
19
  ### ⚠️ Notices
16
20
 
17
21
  - [iOS] Swift conversion 1: badge and server registration. ([#32069](https://github.com/expo/expo/pull/32069) by [@douglowder](https://github.com/douglowder))
18
22
  - [iOS] Swift conversion 2: push token module. ([#32612](https://github.com/expo/expo/pull/32612) by [@douglowder](https://github.com/douglowder))
19
23
  - [iOS] Swift conversion 3: scheduling, notification builder. ([#33253](https://github.com/expo/expo/pull/33253) by [@douglowder](https://github.com/douglowder))
24
+ - [iOS] Swift conversion 4: Categories. ([#33976](https://github.com/expo/expo/pull/33976) by [@douglowder](https://github.com/douglowder))
20
25
 
21
26
  ## 0.29.11 - 2024-12-05
22
27
 
@@ -24,6 +29,7 @@
24
29
 
25
30
  - [android] fix data serialization for notifications with `ChannelAwareTrigger` ([#33354](https://github.com/expo/expo/pull/33354) by [@alextoudic](https://github.com/alextoudic))
26
31
  - Add additional fallback value for project ID in `getExpoPushTokenAsync` ([#33359](https://github.com/expo/expo/pull/33359) by [@bradjones1](https://github.com/bradjones1))
32
+ - [Android] Started using expo modules gradle plugin. ([#34176](https://github.com/expo/expo/pull/34176) by [@lukmccall](https://github.com/lukmccall))
27
33
 
28
34
  ## 0.29.10 - 2024-12-02
29
35
 
@@ -1,16 +1,28 @@
1
1
  apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-parcelize'
3
3
 
4
+ def useLegacyExpoModulesCorePlugin = {
5
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
6
+ apply from: expoModulesCorePlugin
7
+ applyKotlinExpoModulesCorePlugin()
8
+ useCoreDependencies()
9
+ useDefaultAndroidSdkVersions()
10
+ useExpoPublishing()
11
+ }
12
+
13
+ try {
14
+ apply plugin: 'expo-module-gradle-plugin'
15
+ } catch (e) {
16
+ if (!e instanceof UnknownPluginException) {
17
+ throw e
18
+ }
19
+
20
+ useLegacyExpoModulesCorePlugin()
21
+ }
22
+
4
23
  group = 'host.exp.exponent'
5
24
  version = '0.29.8'
6
25
 
7
- def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
8
- apply from: expoModulesCorePlugin
9
- applyKotlinExpoModulesCorePlugin()
10
- useCoreDependencies()
11
- useDefaultAndroidSdkVersions()
12
- useExpoPublishing()
13
-
14
26
  android {
15
27
  namespace "expo.modules.notifications"
16
28
  defaultConfig {
@@ -44,15 +44,15 @@ class PushTokenModule : Module(), PushTokenListener {
44
44
  * @param promise Promise to be resolved with the token.
45
45
  */
46
46
  AsyncFunction("getDevicePushTokenAsync") { promise: Promise ->
47
- FirebaseMessaging.getInstance().token
47
+ val instance = getFirebaseMessagingInstance(promise) ?: return@AsyncFunction
48
+ instance.token
48
49
  .addOnCompleteListener { task ->
49
50
  if (!task.isSuccessful) {
50
51
  val exception = task.exception
51
52
  promise.reject(REGISTRATION_FAIL_CODE, "Fetching the token failed: ${exception?.message ?: "unknown"}", exception)
52
53
  return@addOnCompleteListener
53
54
  }
54
- val token = task.result
55
- if (token == null) {
55
+ val token = task.result ?: run {
56
56
  promise.reject(REGISTRATION_FAIL_CODE, "Fetching the token failed. Invalid token.", null)
57
57
  return@addOnCompleteListener
58
58
  }
@@ -63,7 +63,8 @@ class PushTokenModule : Module(), PushTokenListener {
63
63
  }
64
64
 
65
65
  AsyncFunction("unregisterForNotificationsAsync") { promise: Promise ->
66
- FirebaseMessaging.getInstance().deleteToken()
66
+ val instance = getFirebaseMessagingInstance(promise) ?: return@AsyncFunction
67
+ instance.deleteToken()
67
68
  .addOnCompleteListener { task ->
68
69
  if (!task.isSuccessful) {
69
70
  val exception = task.exception
@@ -75,6 +76,19 @@ class PushTokenModule : Module(), PushTokenListener {
75
76
  }
76
77
  }
77
78
 
79
+ private fun getFirebaseMessagingInstance(promise: Promise): FirebaseMessaging? {
80
+ return try {
81
+ FirebaseMessaging.getInstance()
82
+ } catch (e: IllegalStateException) {
83
+ promise.reject(
84
+ REGISTRATION_FAIL_CODE,
85
+ "Make sure to complete the guide at https://docs.expo.dev/push-notifications/fcm-credentials/ : ${e.message}",
86
+ e
87
+ )
88
+ null
89
+ }
90
+ }
91
+
78
92
  /**
79
93
  * Callback called when [PushTokenManager] gets notified of a new token.
80
94
  * Emits a [NEW_TOKEN_EVENT_NAME] event.
@@ -125,7 +125,7 @@ function parseDateTrigger(trigger) {
125
125
  if (trigger instanceof Date || typeof trigger === 'number') {
126
126
  // TODO @vonovak this branch is not be used by people using TS
127
127
  // but was part of the public api previously so we keep it for a bit for JS users
128
- console.warn(`You are using a deprecated parameter type (${trigger}) for the notification trigger. Use "{ type: 'date', timestamp: someValue }" instead.`);
128
+ console.warn(`You are using a deprecated parameter type (${trigger}) for the notification trigger. Use "{ type: 'date', date: someValue }" instead.`);
129
129
  return { type: 'date', timestamp: toTimestamp(trigger) };
130
130
  }
131
131
  else if (typeof trigger === 'object' &&
@@ -1 +1 @@
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,CA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AAE,GAAG,cAAc,CAAC;gBACnC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE;oBAC9B,MAAM,IAAI,UAAU,CAClB,6DAA6D,OAAO,EAAE,CACvE,CAAC;iBACH;gBACD,MAAM;aACP;YACD,KAAK,MAAM,CAAC,CAAC;gBACX,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;gBAChC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE;oBACzB,MAAM,IAAI,UAAU,CAAC,2DAA2D,IAAI,EAAE,CAAC,CAAC;iBACzF;gBACD,MAAM;aACP;YACD,KAAK,QAAQ,CAAC,CAAC;gBACb,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;gBAClC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,EAAE,EAAE;oBAC7B,MAAM,IAAI,UAAU,CAClB,6DAA6D,MAAM,EAAE,CACtE,CAAC;iBACH;gBACD,MAAM;aACP;SACF;IACH,CAAC,CAAC,CAAC;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, uuid } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport {\n NativeCalendarTriggerInput,\n NativeDailyTriggerInput,\n NativeDateTriggerInput,\n NativeNotificationTriggerInput,\n NativeTimeIntervalTriggerInput,\n NativeWeeklyTriggerInput,\n NativeMonthlyTriggerInput,\n NativeYearlyTriggerInput,\n} from './NotificationScheduler.types';\nimport {\n NotificationRequestInput,\n NotificationTriggerInput,\n SchedulableTriggerInputTypes,\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`](#setnotificationhandlerhandler)\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 * type: SchedulableTriggerInputTypes.TIME_INTERVAL,\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 * type: SchedulableTriggerInputTypes.TIME_INTERVAL,\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\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 const dateTrigger = parseDateTrigger(userFacingTrigger);\n if (dateTrigger) {\n return dateTrigger;\n }\n const calendarTrigger = parseCalendarTrigger(userFacingTrigger);\n if (calendarTrigger) {\n return calendarTrigger;\n }\n const dailyTrigger = parseDailyTrigger(userFacingTrigger);\n if (dailyTrigger) {\n return dailyTrigger;\n }\n const weeklyTrigger = parseWeeklyTrigger(userFacingTrigger);\n if (weeklyTrigger) {\n return weeklyTrigger;\n }\n const monthlyTrigger = parseMonthlyTrigger(userFacingTrigger);\n if (monthlyTrigger) {\n return monthlyTrigger;\n }\n const yearlyTrigger = parseYearlyTrigger(userFacingTrigger);\n if (yearlyTrigger) {\n return yearlyTrigger;\n }\n const timeIntervalTrigger = parseTimeIntervalTrigger(userFacingTrigger);\n if (timeIntervalTrigger) {\n return timeIntervalTrigger;\n }\n return Platform.select({\n default: null, // There's no notion of channels on platforms other than Android.\n android: {\n type: 'channel',\n channelId:\n typeof userFacingTrigger === 'object' &&\n userFacingTrigger !== null &&\n !(userFacingTrigger instanceof Date)\n ? userFacingTrigger?.channelId\n : undefined,\n },\n });\n}\n\nfunction parseCalendarTrigger(\n trigger: NotificationTriggerInput\n): NativeCalendarTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.CALENDAR\n ) {\n const { repeats, ...calendarTrigger } = trigger;\n return { type: 'calendar', value: calendarTrigger, repeats };\n }\n return undefined;\n}\n\nfunction parseDateTrigger(trigger: NotificationTriggerInput): NativeDateTriggerInput | undefined {\n if (trigger instanceof Date || typeof trigger === 'number') {\n // TODO @vonovak this branch is not be used by people using TS\n // but was part of the public api previously so we keep it for a bit for JS users\n console.warn(\n `You are using a deprecated parameter type (${trigger}) for the notification trigger. Use \"{ type: 'date', timestamp: someValue }\" instead.`\n );\n return { type: 'date', timestamp: toTimestamp(trigger) };\n } else if (\n typeof trigger === 'object' &&\n trigger !== null &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.DATE &&\n 'date' in trigger\n ) {\n const result: NativeDateTriggerInput = {\n type: 'date',\n timestamp: toTimestamp(trigger.date),\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n } else {\n return undefined;\n }\n}\n\nfunction toTimestamp(date: number | Date) {\n if (date instanceof Date) {\n return date.getTime();\n }\n return date;\n}\n\nfunction parseDailyTrigger(trigger: NotificationTriggerInput): NativeDailyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.DAILY\n ) {\n validateDateComponentsInTrigger(trigger, ['hour', 'minute']);\n const result: NativeDailyTriggerInput = {\n type: 'daily',\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseWeeklyTrigger(\n trigger: NotificationTriggerInput\n): NativeWeeklyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.WEEKLY\n ) {\n validateDateComponentsInTrigger(trigger, ['weekday', 'hour', 'minute']);\n const result: NativeWeeklyTriggerInput = {\n type: 'weekly',\n weekday: trigger.weekday ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseMonthlyTrigger(\n trigger: NotificationTriggerInput\n): NativeMonthlyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.MONTHLY\n ) {\n validateDateComponentsInTrigger(trigger, ['day', 'hour', 'minute']);\n const result: NativeMonthlyTriggerInput = {\n type: 'monthly',\n day: trigger.day ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseYearlyTrigger(\n trigger: NotificationTriggerInput\n): NativeYearlyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.YEARLY\n ) {\n validateDateComponentsInTrigger(trigger, ['month', 'day', 'hour', 'minute']);\n const result: NativeYearlyTriggerInput = {\n type: 'yearly',\n month: trigger.month ?? placeholderDateComponentValue,\n day: trigger.day ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseTimeIntervalTrigger(\n trigger: NotificationTriggerInput\n): NativeTimeIntervalTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.TIME_INTERVAL &&\n 'seconds' in trigger &&\n typeof trigger.seconds === 'number'\n ) {\n const result: NativeTimeIntervalTriggerInput = {\n type: 'timeInterval',\n seconds: trigger.seconds,\n repeats: trigger.repeats ?? false,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\n// Needed only to satisfy Typescript types for validated date components\nconst placeholderDateComponentValue = -9999;\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 = anyTriggerType.day;\n const month =\n anyTriggerType.month !== undefined ? anyTriggerType.month : new Date().getMonth();\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;AAW5D,OAAO,EAGL,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAA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iBACH;gBACD,MAAM;aACP;YACD,KAAK,MAAM,CAAC,CAAC;gBACX,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;gBAChC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE;oBACzB,MAAM,IAAI,UAAU,CAAC,2DAA2D,IAAI,EAAE,CAAC,CAAC;iBACzF;gBACD,MAAM;aACP;YACD,KAAK,QAAQ,CAAC,CAAC;gBACb,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;gBAClC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,EAAE,EAAE;oBAC7B,MAAM,IAAI,UAAU,CAClB,6DAA6D,MAAM,EAAE,CACtE,CAAC;iBACH;gBACD,MAAM;aACP;SACF;IACH,CAAC,CAAC,CAAC;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, uuid } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport {\n NativeCalendarTriggerInput,\n NativeDailyTriggerInput,\n NativeDateTriggerInput,\n NativeNotificationTriggerInput,\n NativeTimeIntervalTriggerInput,\n NativeWeeklyTriggerInput,\n NativeMonthlyTriggerInput,\n NativeYearlyTriggerInput,\n} from './NotificationScheduler.types';\nimport {\n NotificationRequestInput,\n NotificationTriggerInput,\n SchedulableTriggerInputTypes,\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`](#setnotificationhandlerhandler)\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 * type: SchedulableTriggerInputTypes.TIME_INTERVAL,\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 * type: SchedulableTriggerInputTypes.TIME_INTERVAL,\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\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 const dateTrigger = parseDateTrigger(userFacingTrigger);\n if (dateTrigger) {\n return dateTrigger;\n }\n const calendarTrigger = parseCalendarTrigger(userFacingTrigger);\n if (calendarTrigger) {\n return calendarTrigger;\n }\n const dailyTrigger = parseDailyTrigger(userFacingTrigger);\n if (dailyTrigger) {\n return dailyTrigger;\n }\n const weeklyTrigger = parseWeeklyTrigger(userFacingTrigger);\n if (weeklyTrigger) {\n return weeklyTrigger;\n }\n const monthlyTrigger = parseMonthlyTrigger(userFacingTrigger);\n if (monthlyTrigger) {\n return monthlyTrigger;\n }\n const yearlyTrigger = parseYearlyTrigger(userFacingTrigger);\n if (yearlyTrigger) {\n return yearlyTrigger;\n }\n const timeIntervalTrigger = parseTimeIntervalTrigger(userFacingTrigger);\n if (timeIntervalTrigger) {\n return timeIntervalTrigger;\n }\n return Platform.select({\n default: null, // There's no notion of channels on platforms other than Android.\n android: {\n type: 'channel',\n channelId:\n typeof userFacingTrigger === 'object' &&\n userFacingTrigger !== null &&\n !(userFacingTrigger instanceof Date)\n ? userFacingTrigger?.channelId\n : undefined,\n },\n });\n}\n\nfunction parseCalendarTrigger(\n trigger: NotificationTriggerInput\n): NativeCalendarTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.CALENDAR\n ) {\n const { repeats, ...calendarTrigger } = trigger;\n return { type: 'calendar', value: calendarTrigger, repeats };\n }\n return undefined;\n}\n\nfunction parseDateTrigger(trigger: NotificationTriggerInput): NativeDateTriggerInput | undefined {\n if (trigger instanceof Date || typeof trigger === 'number') {\n // TODO @vonovak this branch is not be used by people using TS\n // but was part of the public api previously so we keep it for a bit for JS users\n console.warn(\n `You are using a deprecated parameter type (${trigger}) for the notification trigger. Use \"{ type: 'date', date: someValue }\" instead.`\n );\n return { type: 'date', timestamp: toTimestamp(trigger) };\n } else if (\n typeof trigger === 'object' &&\n trigger !== null &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.DATE &&\n 'date' in trigger\n ) {\n const result: NativeDateTriggerInput = {\n type: 'date',\n timestamp: toTimestamp(trigger.date),\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n } else {\n return undefined;\n }\n}\n\nfunction toTimestamp(date: number | Date) {\n if (date instanceof Date) {\n return date.getTime();\n }\n return date;\n}\n\nfunction parseDailyTrigger(trigger: NotificationTriggerInput): NativeDailyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.DAILY\n ) {\n validateDateComponentsInTrigger(trigger, ['hour', 'minute']);\n const result: NativeDailyTriggerInput = {\n type: 'daily',\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseWeeklyTrigger(\n trigger: NotificationTriggerInput\n): NativeWeeklyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.WEEKLY\n ) {\n validateDateComponentsInTrigger(trigger, ['weekday', 'hour', 'minute']);\n const result: NativeWeeklyTriggerInput = {\n type: 'weekly',\n weekday: trigger.weekday ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseMonthlyTrigger(\n trigger: NotificationTriggerInput\n): NativeMonthlyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.MONTHLY\n ) {\n validateDateComponentsInTrigger(trigger, ['day', 'hour', 'minute']);\n const result: NativeMonthlyTriggerInput = {\n type: 'monthly',\n day: trigger.day ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseYearlyTrigger(\n trigger: NotificationTriggerInput\n): NativeYearlyTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.YEARLY\n ) {\n validateDateComponentsInTrigger(trigger, ['month', 'day', 'hour', 'minute']);\n const result: NativeYearlyTriggerInput = {\n type: 'yearly',\n month: trigger.month ?? placeholderDateComponentValue,\n day: trigger.day ?? placeholderDateComponentValue,\n hour: trigger.hour ?? placeholderDateComponentValue,\n minute: trigger.minute ?? placeholderDateComponentValue,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\nfunction parseTimeIntervalTrigger(\n trigger: NotificationTriggerInput\n): NativeTimeIntervalTriggerInput | undefined {\n if (\n trigger !== null &&\n typeof trigger === 'object' &&\n 'type' in trigger &&\n trigger.type === SchedulableTriggerInputTypes.TIME_INTERVAL &&\n 'seconds' in trigger &&\n typeof trigger.seconds === 'number'\n ) {\n const result: NativeTimeIntervalTriggerInput = {\n type: 'timeInterval',\n seconds: trigger.seconds,\n repeats: trigger.repeats ?? false,\n };\n if (trigger.channelId) {\n result.channelId = trigger.channelId;\n }\n return result;\n }\n return undefined;\n}\n\n// Needed only to satisfy Typescript types for validated date components\nconst placeholderDateComponentValue = -9999;\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 = anyTriggerType.day;\n const month =\n anyTriggerType.month !== undefined ? anyTriggerType.month : new Date().getMonth();\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,9 +1,15 @@
1
1
  {
2
- "name": "expo-notifications",
3
- "platforms": ["ios", "android"],
4
- "ios": {
5
- "modules": ["BadgeModule", "ServerRegistrationModule", "PushTokenModule", "SchedulerModule", "PresentationModule"],
6
- "appDelegateSubscribers": ["PushTokenAppDelegateSubscriber"]
2
+ "platforms": ["apple", "android"],
3
+ "apple": {
4
+ "modules": [
5
+ "BadgeModule",
6
+ "CategoriesModule",
7
+ "PresentationModule",
8
+ "PushTokenModule",
9
+ "ServerRegistrationModule",
10
+ "SchedulerModule"
11
+ ],
12
+ "appDelegateSubscribers": ["NotificationsAppDelegateSubscriber"]
7
13
  },
8
14
  "android": {
9
15
  "modules": [
@@ -0,0 +1,48 @@
1
+ // Copyright © 2024 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+ import UIKit
5
+ import MachO
6
+
7
+ public class CategoriesModule: Module {
8
+ public func definition() -> ModuleDefinition {
9
+ Name("ExpoNotificationCategoriesModule")
10
+
11
+ AsyncFunction("getNotificationCategoriesAsync") { (promise: Promise) in
12
+ UNUserNotificationCenter.current().getNotificationCategories { categories in
13
+ let existingCategories = categories.map { category in
14
+ return CategoryRecord(category)
15
+ }
16
+ promise.resolve(existingCategories)
17
+ }
18
+ }
19
+
20
+ AsyncFunction("setNotificationCategoryAsync") { (identifier: String, actions: [CategoryActionRecord], options: CategoryOptionsRecord?, promise: Promise) in
21
+ let categoryRecord = CategoryRecord(identifier, actions: actions, options: options)
22
+ let newNotificationCategory = categoryRecord.toUNNotificationCategory()
23
+ UNUserNotificationCenter.current().getNotificationCategories { oldcategories in
24
+ let newCategories = Set(oldcategories.filter { oldCategory in
25
+ return oldCategory.identifier != newNotificationCategory.identifier
26
+ }
27
+ .union([newNotificationCategory]))
28
+ UNUserNotificationCenter.current().setNotificationCategories(newCategories)
29
+ promise.resolve(CategoryRecord(newNotificationCategory))
30
+ }
31
+ }
32
+
33
+ AsyncFunction("deleteNotificationCategoryAsync") { (identifier: String, promise: Promise) in
34
+ UNUserNotificationCenter.current().getNotificationCategories { oldCategories in
35
+ let didDelete = oldCategories.contains { oldCategory in
36
+ return oldCategory.identifier == identifier
37
+ }
38
+ if didDelete {
39
+ let newCategories = Set(oldCategories.filter { oldCategory in
40
+ return oldCategory.identifier != identifier
41
+ })
42
+ UNUserNotificationCenter.current().setNotificationCategories(newCategories)
43
+ }
44
+ promise.resolve(didDelete)
45
+ }
46
+ }
47
+ }
48
+ }
@@ -1,3 +1,5 @@
1
+ // Copyright © 2024 650 Industries. All rights reserved.
2
+
1
3
  import ExpoModulesCore
2
4
  import Foundation
3
5
 
@@ -1,7 +1,7 @@
1
1
  import ExpoModulesCore
2
2
  import Foundation
3
3
 
4
- public class PushTokenAppDelegateSubscriber: ExpoAppDelegateSubscriber {
4
+ public class NotificationsAppDelegateSubscriber: ExpoAppDelegateSubscriber {
5
5
  let notificationCenterManager = NotificationCenterManager.shared
6
6
 
7
7
  public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
@@ -25,7 +25,8 @@ public class PresentationModule: Module, NotificationDelegate {
25
25
  promise.reject("ERR_NOTIF_PRESENT", error.localizedDescription)
26
26
  return
27
27
  }
28
- let content = try NotificationBuilder.content(notificationSpec, appContext: appContext)
28
+ let requestContentRecord = try NotificationRequestContentRecord(from: notificationSpec, appContext: appContext)
29
+ let content = requestContentRecord.toUNMutableNotificationContent()
29
30
  var request: UNNotificationRequest?
30
31
  try EXUtilities.catchException {
31
32
  request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil)