expo-notifications
@amazon-devices/expo-notificationsは、ローカル通知を表示、消去、取得するためのAPIを提供します。
このライブラリはシステムにデプロイされるため、別途インストールプロセスを必要とすることなくVega向けReact Nativeアプリで利用できます。これは、アプリが実行時にリンクする自動リンクライブラリとしてデプロイされます。ライブラリとVega向けReact Nativeとの互換性は、ライブラリがターゲットとしているVega向けReact Nativeバージョンとの間でのみ保証されます。
インストール
package.jsonファイルにJavaScriptライブラリの依存関係を追加します。"dependencies": { ... "@amazon-devices/expo-notifications": "~2.0.0", "expo": "~50.0.0", ... }-
npm installコマンドを使用して、依存関係を再インストールします。 manifest.tomlファイルを更新します。[needs] ... [[needs.privilege]] id = "com.amazon.notification.privilege.post" [[needs.privilege]] id = "com.amazon.notification.privilege.query"npm run build:appコマンドを使用してアプリを再ビルドします。
例
ローカル通知のスケジュール、一覧の取得、消去の例を以下に示します。
import * as Notifications from '@amazon-devices/expo-notifications';
import {
Importance,
InformationKind,
} from '@amazon-devices/expo-notifications/build/kepler';
import React, {useState} from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
export const App = () => {
const [result, setResult] = useState('');
const presentLocalNotificationAsync = async () => {
const id = await Notifications.scheduleNotificationAsync({
content: {
title: 'テスト通知',
subtitle: 'サブタイトル',
body: '本文です',
data: {},
iconUri: 'https://example.org',
channel: {
name: 'テストチャネル',
description: 'デモアプリのテストチャネルの説明文が入ります',
importance: {
importance: Importance.IMPORTANCE_LOW,
},
kind: new InformationKind(),
},
sound: false,
},
trigger: null,
});
setResult(`表示された通知 ${id}`);
};
const listLocalNotificationsAsync = async () => {
const res = await Notifications.getPresentedNotificationsAsync();
setResult(JSON.stringify(res, null, 2));
};
const countPresentedNotifications = async () => {
const presentedNotifications =
await Notifications.getPresentedNotificationsAsync();
setResult(`カウント: ${presentedNotifications.length}`);
};
const dismissAll = async () => {
await Notifications.dismissAllNotificationsAsync();
setResult('通知がされました');
};
const dismissSingle = async () => {
const presentedNotifications =
await Notifications.getPresentedNotificationsAsync();
if (!presentedNotifications.length) {
setResult('消去すべき通知はありません');
return;
}
const lastNotificationUuid = presentedNotifications[0].request.identifier;
await Notifications.dismissNotificationAsync(lastNotificationUuid);
setResult(`通知:${lastNotificationUuid}が消去されました`);
};
return (
<View style={styles.container}>
<Text style={styles.text}>Local Notifications</Text>
<Button
onPress={presentLocalNotificationAsync}
title="通知をすぐに表示する"
/>
<Button
onPress={listLocalNotificationsAsync}
title="すべての通知を表示"
/>
<Button
onPress={countPresentedNotifications}
title="表示された通知の数をカウント"
/>
<Text style={styles.text}>通知を消去</Text>
<Button onPress={dismissSingle} title="1件の通知を消去" />
<Button onPress={dismissAll} title="すべての通知を消去" />
<View style={{flex: 1}}>
{result && (
<Text style={styles.text}>
Last Result:{'\n'}
{result}
</Text>
)}
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
text: {
color: 'black',
fontSize: 32,
},
});
APIリファレンス
このライブラリの情報、APIリファレンス、その他の詳細については、 Expo公式ドキュメントのexpo-notificationsのページ(英語のみ)を参照してください。
このドキュメントはすべてのプラットフォームに適用され、Vegaでサポートされていないメソッドも含まれていることに注意してください。
メソッド
| メソッド | 説明 | 対応プラットフォーム |
|---|---|---|
| addPushTokenListener | まれに、アプリの実行中にプッシュ通知サービスによってプッシュトークンが変更されることがあります。トークンが更新されると、古いトークンは無効になり、その古いトークンに通知を送信しても失敗します。プッシュトークンリスナーを使用すると、新しいトークンをバックエンドにすぐに登録するため、このような状況に適切に対処できます。 | Android、iOS |
| getDevicePushTokenAsync | ネイティブのFCM/APNsトークン、または別のプッシュ通知サービスで使用できるPushSubscriptionデータを返します。 |
Android、iOS |
| getExpoPushTokenAsync | Expoトークンを返します。これは、Expoのプッシュ通知サービスでデバイスにプッシュ通知を送信するために使用できます。 | Android、iOS |
| removePushTokenSubscription | addPushTokenListener呼び出しによって返されたプッシュトークンのサブスクリプションを解除します。 |
Android、iOS |
| addNotificationReceivedListener | このメソッドで登録されたリスナーは、アプリの実行中に通知を受信するたびに呼び出されます。 | Android、iOS |
| addNotificationResponseReceivedListener | このメソッドで登録されたリスナーは、ユーザーが通知を操作する(たとえば、通知をタップする)たびに呼び出されます。 | Android、iOS |
| addNotificationsDroppedListener | このメソッドで登録されたリスナーは、サーバーによって通知がドロップされるたびに呼び出されます。Androidで通知サービスとして使用しているFirebase Cloud Messagingにのみ適用されます。また、onDeletedMessages()コールバックに対応します。詳細については、Firebaseのドキュメントを参照してください。 | Android、iOS |
| getLastNotificationResponseAsync | 最後に受信した通知レスポンスを返します(通知レスポンスとは、通知をタップするなどの通知との対話操作を指します)。 | Android、iOS |
| removeNotificationSubscription | addNotificationListener呼び出しによって返された通知のサブスクリプションを解除します。 |
Android、iOS |
| setNotificationHandler | アプリの実行中に通知を受け取った場合、この関数を使用して、通知をユーザーに表示するかどうかを決定するコールバックを設定できます。 | Android、iOS |
| registerTaskAsync | アプリがバックグラウンドで動作しているときに通知を受け取った場合、この関数を使用して、その通知に応答して実行されるコールバックを設定できます。内部的には、この関数はexpo-task-managerを使用して実行されます。最初に、TaskManager.defineTaskを使用してタスクを定義する必要があります。必ずグローバルスコープで定義してください。 |
Android、iOS |
| unregisterTaskAsync | registerTaskAsyncメソッドで登録されたタスクの登録を解除するために使用します。 |
Android、iOS |
| getPermissionsAsync | この関数は、通知に関連する現在の権限設定をチェックします。アプリが現在アラートの表示や、サウンドの再生などを許可されているかどうかを確認できます。これを呼び出すことによるユーザーへの影響はありません。 | Android、iOS |
| requestPermissionsAsync | リクエストに応じて、ユーザーに通知権限を求める表示がされます。リクエストはデフォルトで、アラートの表示、バッジ数の設定、サウンドの再生を許可するようユーザーに要求します。 | Android、iOS |
| getBadgeCountAsync | デバイスのホーム画面で、アプリアイコンに現在設定されているバッジ数を取得します。値が0の場合は、バッジが表示されていないことを意味します。 |
Android、iOS |
| setBadgeCountAsync | アプリアイコンのバッジを指定された数に設定します。0に設定するとバッジがクリアされます。iOS では、このメソッドを使用するにはrequestPermissionsAsyncを使用し、allowBadgeに対するユーザーの権限をリクエストしておく必要があります。これを行わないと、自動的にfalseが返されます。 |
Android、iOS |
| cancelAllScheduledNotificationsAsync | スケジュールされたすべての通知をキャンセルします。 | Android、iOS |
| cancelScheduledNotificationAsync | 1件のスケジュールされた通知をキャンセルします。指定されたIDのスケジュール通知はトリガーされません。 | Android、iOS |
| getAllScheduledNotificationsAsync | スケジュールされたすべての通知に関する情報を取得します。 | Android、iOS |
| getNextTriggerDateAsync | 指定された通知トリガー入力の、次のトリガー日を確認できます。 | Android、iOS |
| presentNotificationAsync | すぐにトリガーされる通知をスケジュールします。 | Android、iOS |
| scheduleNotificationAsync | 今後トリガーされる通知をスケジュールします。 | すべて |
| dismissAllNotificationsAsync | 通知トレイ(通知センター)に表示されているすべてのアプリの通知を削除します。 | すべて |
| dismissNotificationAsync | 通知トレイ(通知センター)に表示されている通知を削除します。 | すべて |
| getPresentedNotificationsAsync | 通知トレイ(通知センター)にあるすべての通知に関する情報を取得します。 | すべて |
| deleteNotificationChannelAsync | 通知チャネルを削除します。 | Android |
| deleteNotificationChannelGroupAsync | 通知チャネルグループと、それに属するすべての通知チャネルを削除します。 | Android |
| getNotificationChannelAsync | 1つの通知チャネルに関する情報を取得します。 | Android |
| getNotificationChannelGroupAsync | 1つの通知チャネルグループに関する情報を取得します。 | Android |
| getNotificationChannelGroupsAsync | すべての既知の通知チャネルグループに関する情報を取得します。 | Android |
| getNotificationChannelsAsync | すべての既知の通知チャネルに関する情報を取得します。 | Android |
| setNotificationChannelAsync | 指定された名前のチャンネルに、チャンネル構成を割り当てます(必要に応じて作成します)。このメソッドを使用すると、指定された通知チャネルを通知チャネルグループに割り当てることができます。 | Android |
| setNotificationChannelGroupAsync | 指定された名前のチャンネルグループに、チャンネルグループ構成を割り当てます(必要に応じて作成します)。 | Android |
| deleteNotificationCategoryAsync | 指定された識別子に関連付けられているカテゴリーを削除します。 | Android、iOS |
| getNotificationCategoriesAsync | 既知のすべての通知カテゴリーに関する情報を取得します。 | Android、iOS |
| setNotificationCategoryAsync | 新しい通知カテゴリーを設定します。 | Android、iOS |
| setAutoServerRegistrationEnabledAsync | 登録情報を設定し、指定された登録エンドポイントにデバイスのプッシュトークンがプッシュされるようにします。 | Android、iOS |
| unregisterForNotificationsAsync | 現在のデバイスにおけるプッシュ通知の受信をキャンセルします。 | Android、iOS |
フック
| フック | 説明 | 対応プラットフォーム |
|---|---|---|
| useLastNotificationResponse | 最後に受信した通知レスポンスを返すReactフックです(通知レスポンスとは、通知をタップするなどの通知との対話操作を指します)。 | Android、iOS |
実装の詳細
このライブラリは現在、Vega仮想デバイスでは動作しません。
Vegaでは、プッシュ通知、ローカル通知のトリガー、アプリバッジはサポートされません。
サポートされているメソッドの一覧は次のとおりです。
scheduleNotificationAsyncgetPresentedNotificationsAsyncdismissNotificationAsyncdismissAllNotificationsAsync
このパッケージにはVegaの通知チャネルのサポートも含まれていますが、これらのチャネルはAndroidのように事前に作成されるのではなく、通知の設定時にscheduleNotificationAsyncに提供されます。そのため、@amazon-devices/expo-notificationsにはチャネル関連のメソッドは実装されていません。
サポートされているバージョン
| NPMパッケージのバージョン | Vega SDKバージョン | Vega OSバージョン | React Nativeバージョン |
|---|---|---|---|
| ~2.0.0 | 0.23以前 | OS 1.1(1401010009820)以前 |
0.72 |
関連リソース
その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。
Last updated: 2026年8月3日

