<p>
<a href="https://docs.expo.dev/versions/latest/sdk/notifications/">
<img
src="../../.github/resources/expo-notifications.svg"
alt="expo-notifications"
height="64" />
</a>
</p>
Provides an API to fetch push notification tokens and to present, schedule, receive and respond to notifications.
## Features
- ð£ schedule a one-off notification for a specific date, or some time from now,
- ð schedule a notification repeating in some time interval (or a calendar date match on iOS),
- 1ï¸â£ get and set application badge icon number,
- ð² fetch a native device push token so you can send push notifications with FCM and APNS,
- ð fetch an Expo push token so you can send push notifications with Expo,
- ð¬ listen to incoming notifications in the foreground and background,
- ð listen to interactions with notifications (tapping or dismissing),
- ð handle notifications when the app is in foreground,
- ð imperatively dismiss notifications from Notification Center/tray,
- ð create, update, delete Android notification channels,
- ð¨ set custom icon and color for notifications on Android.
# Installation in managed Expo projects
Please refer to the [installation instructions in the Expo documentation](https://docs.expo.dev/versions/latest/sdk/notifications/#installation).
# Installation in bare React Native projects
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
### Add the package to your npm dependencies
```
npx expo install expo-notifications
```
### Configure for iOS
Run `npx pod-install` after installing the npm package.
In order to be able to receive push notifications on the device:
- open Xcode workspace from your `ios` folder
- select your project from the _Navigator_ pane
- switch to _Signing & Capabilities_ tab
- ensure that the _Push notifications_ capability is present (if it's not, click the "+ Capability" button and add the capability to the project).
### Configure for Android
In order to be able to receive push notifications on the device ensure that your project is set up for Firebase. For more information on how to do it, see [this guide](https://docs.expo.dev/guides/setup-native-firebase/#bare-workflow-setup).
This module requires permission to subscribe to device boot. It's used to setup the scheduled notifications right after the device (re)starts. The `RECEIVE_BOOT_COMPLETED` permission is added automatically.
**Note:** Starting from Android 12 (API level 31), to schedule the notification that triggers at the exact time, you need to add `<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>` to **AndroidManifest.xml**. You can read more about the exact alarm permission [here](https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission).
<details><summary><strong>Expand to view how the notification icon and the default color can be customized in a plain React Native app</strong></summary> <p>
- **To customize the icon**:
You can customize two icons: the default and the large one. See [the Android documentation](https://developer.android.com/guide/topics/ui/notifiers/notifications#Templates) for more details. The steps for them are very similar. The only difference is the tag in the second step.
1. You will need to ensure that the icon is properly set up and added the project. To read more on how to create a notification icon and add it to the project check out the [âCreate notification iconâ section](https://developer.android.com/studio/write/image-asset-studio#create-notification) at the official Android guide. Remember the name you use for the icon asset, you will need it later!
2. Then head over to `android/app/src/main/AndroidManifest.xml` and add a `<meta-data>` tag of `android:name="expo.modules.notifications.default_notification_icon"` (or `android:name="expo.modules.notifications.large_notification_icon"` if you are changing the large icon) inside the `<application>` node referencing the custom icon with `@drawable/<notification_icon_name_you_used_in_step_1>`, like [here](https://github.com/expo/expo/blob/335e67a1a3a91598c02061f3318a881541d0d57a/apps/bare-expo/android/app/src/main/AndroidManifest.xml#L44-L46).
3. In the end your `AndroidManifest.xml` should look more or less like this:
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
...
<application ...>
...
<meta-data
android:name="expo.modules.notifications.default_notification_icon"
android:resource="@drawable/ic_stat_notifications" /> <!-- @drawable/<insert_notification_icon_name> -->
...
</application>
</manifest>
```
- **To customize the default color of the notification**:
1. you will need a color resource added to the native project's resources. Some information on how to do this can be found in [the official Android guide](https://developer.android.com/guide/topics/resources/more-resources#Color). The most simple and fail-safe instructions would be to:
1. ensure that there is a file under `android/app/src/main/res/values/colors.xml` (if there is none, create it)
2. ensure that it's a valid resources XML file (it should start with a `<?xml version="1.0" encoding="utf-8"?>` declaration and have a root node of `<resources>`)
3. inside the `<resources>` node add a `<color>` node with an arbitrary name (like `notification_icon_color`) containing the color in HEX format inside, like [here](https://github.com/expo/expo/blob/335e67a1a3a91598c02061f3318a881541d0d57a/apps/bare-expo/android/app/src/main/res/values/colors.xml#L3).
4. in the end your `colors.xml` should look more or less like this:
```java
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="notification_icon_color">#4630EB</color>
</resources>
```
2. now, when the color is added to the project, we need to configure `expo-notifications` to use it when it displays a notification â head over to `android/app/src/main/AndroidManifest.xml` and add a `<meta-data>` tag of `android:name="expo.modules.notifications.default_notification_color"` inside the `<application>` node referencing the custom icon with `@color/<notification_icon_color_name>`, like [here](https://github.com/expo/expo/blob/335e67a1a3a91598c02061f3318a881541d0d57a/apps/bare-expo/android/app/src/main/AndroidManifest.xml#L47-L49).
3. In the end your `AndroidManifest.xml` should look more or less like this:
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
...
<application ...>
...
<meta-data
android:name="expo.modules.notifications.default_notification_color"
android:resource="@color/notification_icon_color" /> <!-- @color/<insert_notification_icon_color_name> -->
...
</application>
</manifest>
```
- An `AndroidManifest.xml` with both color (of name `notification_icon_color`) and an icon (of name `ic_stat_notifications`) name would look like this:
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<application ...>
...
<meta-data
android:name="expo.modules.notifications.default_notification_icon"
android:resource="@drawable/ic_stat_notifications" />
<meta-data
android:name="expo.modules.notifications.default_notification_color"
android:resource="@color/notification_icon_color" />
...
</application>
</manifest>
```
</p>
</details>
### Config plugin setup (optional)
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/introductio
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
跨平台应用开发框架:该框架用于构建Android、iOS和网页应用程序 (2000个子文件)
NativeReanimatedModule.cpp 25KB
NativeProxy.cpp 20KB
Shareables.cpp 12KB
JsiValue.cpp 10KB
JSISerializer.cpp 9KB
NativeReanimatedModuleSpec.cpp 7KB
RNSkJsView.cpp 7KB
RNSkDomView.cpp 7KB
JniPlatformContext.cpp 6KB
LayoutAnimationsManager.cpp 6KB
WorkletRuntimeDecorator.cpp 5KB
CSSColorParser.cpp 5KB
JsiHostObject.cpp 5KB
ReanimatedHermesRuntime.cpp 4KB
SkiaOpenGLSurfaceFactory.cpp 4KB
LayoutAnimations.cpp 4KB
ConcatablePaint.cpp 4KB
EventHandlerRegistry.cpp 3KB
AnimatedSensorModule.cpp 3KB
WorkletRuntime.cpp 3KB
RNSkManager.cpp 3KB
ReanimatedVersion.cpp 3KB
UIRuntimeDecorator.cpp 2KB
RNSkOpenGLCanvasProvider.cpp 2KB
ReanimatedCommitHook.cpp 2KB
ShadowTreeCloner.cpp 2KB
RuntimeLifecycleMonitor.cpp 2KB
RNSkDispatchQueue.cpp 2KB
JNIHelper.cpp 2KB
AndroidUIScheduler.cpp 2KB
ReanimatedRuntime.cpp 2KB
RNRuntimeDecorator.cpp 2KB
JsiPromises.cpp 1KB
cpp-adapter.cpp 1KB
DrawingContext.cpp 1KB
JniSkiaManager.cpp 1KB
TurboModule.cpp 1KB
AsyncQueue.cpp 1KB
PropsRegistry.cpp 1KB
ReanimatedMountHook.cpp 972B
ReanimatedJSIUtils.cpp 735B
AndroidLogger.cpp 719B
WorkletEventHandler.cpp 704B
OnLoad.cpp 616B
ReanimatedCommitMarker.cpp 582B
JniLoad.cpp 544B
registration.cpp 456B
JSLogger.cpp 438B
rnscreens.cpp 433B
UIScheduler.cpp 363B
JSScheduler.cpp 268B
WorkletRuntimeRegistry.cpp 195B
RuntimeAwareCache.cpp 134B
FeaturesConfig.cpp 110B
empty.cpp 36B
empty.cpp 36B
global.css 144B
vulkan_core.h 654KB
SkCanvas.h 115KB
SkPath.h 78KB
SkMatrix.h 72KB
Transform_inl.h 54KB
GrDirectContext.h 54KB
SkBitmap.h 53KB
SkRect.h 49KB
SkImage.h 43KB
GrTypesPriv.h 40KB
SkCodec.h 39KB
SkImageFilters.h 35KB
SkPixmap.h 31KB
SkSurface.h 30KB
GrGLFunctions.h 26KB
SkPaint.h 25KB
SkImageInfo.h 24KB
SkRegion.h 23KB
SkTextBlob.h 22KB
JsiSkPath.h 21KB
SkFont.h 21KB
SkTArray.h 21KB
SkGradientShader.h 21KB
SkImageGanesh.h 20KB
JsiSkCanvas.h 20KB
SkRuntimeEffect.h 20KB
SkTypeface.h 20KB
SkRRect.h 20KB
SkPathPriv.h 20KB
SkTHash.h 19KB
SkSVGTypes.h 19KB
SkPathRef.h 19KB
Image.h 18KB
skcms.h 18KB
SkMesh.h 18KB
SkStream.h 18KB
GrGLInterface.h 17KB
SkPoint_impl.h 17KB
SkColor.h 16KB
GrBackendSurface.h 16KB
JsiDomNode.h 15KB
JsiShaderNodes.h 15KB
SkM44.h 14KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
UnknownToKnown
- 粉丝: 1w+
- 资源: 550
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功