首页指南参考教程

获取用于发送到 FCM 或 APN 的设备令牌

了解如何获取原生设备令牌。


在直接与 FCM 和 APN 通信之前,你需要在应用中进行一项客户端更改。使用 Expo 的通知服务时,你需要收集 ExponentPushTokengetExpoPushTokenAsync。现在你没有使用 Expo 的通知服务,你需要使用 getDevicePushTokenAsync 来收集原生设备令牌。

¥Before communicating directly with FCM and APNs, there is one client-side change you'll need to make in your app. When using Expo's notification service, you collect the ExponentPushToken with getExpoPushTokenAsync. Now that you're not using Expo's notification service, you'll need to collect the native device token instead with getDevicePushTokenAsync.

import * as Notifications from 'expo-notifications';
...
- const token = (await Notifications.getExpoPushTokenAsync()).data;
+ const token = (await Notifications.getDevicePushTokenAsync()).data;
// send token to your server

获取原生设备令牌后,你可以启动 在此文件中实现服务器

¥After getting the native device token, you can start implementing the servers.

Expo 中文网 - 粤ICP备13048890号