【发布时间】:2019-11-07 03:20:08
【问题描述】:
我正在尝试使用 Expo 发送推送通知,但我收到了它。但是我的设备上没有振动或声音,也没有弹出。我正在使用带有 Android 9 的 Galaxy S9。我还没有在 Iphone 上尝试过。
推送通知由 nodejs 发送,安装该应用的用户将收到推送通知。用户博览会令牌保存在 firebase 数据库中。我成功保存并获取令牌。
以下来自expo app
class App extends Component {
componentWillMount() {
firebase.initializeApp(config);
this.registerForPushNotificationsAsync();
}
async registerForPushNotificationsAsync(){
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (Platform.OS === 'android') {
Notifications.createChannelAndroidAsync('chat-messages', {
name: 'Chat messages',
sound: true,
priority: 'high', // was max
vibrate: [0, 250, 250, 250],
});
}
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
以下来自nodejs服务器端
function sendMessage(to, title, body) {
const expo = new Expo();
let messages = [];
messages.push({
to, // Expo user token
body,
data: { withSome: 'data' },
ios: {
sound: true
},
android: {
"channelId": "chat-messages" //and this
}
})
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
for (let chunk of chunks) {
try {
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
tickets.push(...ticketChunk);
} catch (error) {
console.error(error);
}
}
})();
}
当用户点击推送通知时我们也可以重定向到网页吗?
【问题讨论】:
标签: react-native push-notification expo