我尝试了以下代码:
const sendPushNotification = async (vendor_token, user_message) => {
const message = {
to: vendor_token,
priority: Platform.OS === 'android' ? "normal" : "high",
sound: "default",
title: 'Order Detail',
body: user_message,
data: { data: 'goes here' },
_displayInForeground: true,
};
const response = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
});
const data = response._bodyInit;
console.log(`Status & Response ID-> ${JSON.stringify(data)}`);
};
但是,如果添加声音:对于Android通知,则为true。
答案 0 :(得分:0)
const sendPushNotification =异步(vendor_token,user_message)=> {
const message = {
to: vendor_token,
priority: Platform.OS === 'android' ? "normal" : "high",
sound: "default",
title: 'Order Detail',
body: user_message,
data: { data: 'goes here' },
_displayInForeground: true,
channelId: "chat-messages",`enter code here`
};
const response = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
});
const data = response._bodyInit;
console.log(`Status & Response ID-> ${JSON.stringify(data)}`);
};
只需在代码中添加“ channelId:”聊天消息“ ,并且android通知声音即可正常运行