[英]How to handle expo push notification icon in 2022?
根据文档,您需要做的就是在 app.json 中设置一些键
在托管工作流程中,在 app.json 中设置您的 notification.icon 和 notification.color 键,重新构建您的应用程序,一切顺利!
对于裸工作流和 EAS Build 用户,您需要配置插件部分:
"plugins": [
[
"expo-notifications",
{
"icon": "./local/assets/notification-icon.png",
"color": "#ffffff",
"sounds": [
"./local/assets/notification-sound.wav",
"./local/assets/notification-sound-other.wav"
]
}
]
]
唯一的问题是这些解决方案都不起作用,我认为问题可能出在图标上,因为文档还说:
对于您的通知图标,请确保您遵循 Google 的设计指南(图标必须全白,背景透明),否则可能无法按预期显示。
因此,我尝试使用资产文件夹中的标准 expoadaptive-icon.png 与推送通知中显示为图标的 expo 徽标不同,但不,它也不起作用。 有人可以告诉我该怎么做吗? 这是我的应用程序。json
{
"expo": {
"name": "my-app",
"slug": "my-app",
"version": "1.0.0",
"orientation": "portrait",
"privacy": "unlisted",
"icon": "./assets/adaptive-icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#C3F458"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"config": {
"googleMapsApiKey": "AIzaSyaAWAQ-4X_hhkQsczxr6oJFWbgeyidWEDasSczLxzlOE2xWNHeY8"
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#C3F458"
},
"config": {
"googleMaps": {
"apiKey": "AIzaSyaAWAQ-4X_hhkQsczxr6oJFWbgeyidWEDasSczLxzlOE2xWNHeY8"
}
}
},
"web": {
"favicon": "./assets/favicon.png"
},
"notification": {
"icon": "./assets/adaptive-icon.png",
"color": "#C3F458"
},
"plugins": [
[
"expo-notifications",
{
"icon": "./assets/adaptive-icon.png",
"color": "#ffffff",
"sounds": []
}
]
]
}
}
我还尝试更改组件中 schedulePushNotification 处理程序的颜色,如下所示:
async function schedulePushNotification() {
await Notifications.scheduleNotificationAsync({
content: {
autoDismiss: false,
color: "#AEDE2D",
title: "hey",
body: "hello",
data: { data: "goes here" },
},
trigger: { seconds: 3 },
});
}
尽管我已将 autoDismiss 设置为 false,但几秒钟后它就会消失,并且 id 没有采用请求的颜色。 在组件定义上方的 App.tsx 中,我有一个 function
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
就像他们在文档https://docs.expo.dev/versions/latest/sdk/notifications/中显示的那样,而不是在组件中我确实导入 * 作为来自“expo-notifications”的通知; 我在上面的 schedulePushNotification 处理程序中使用它,它是否调用了同一个 object?
"notification": {
"icon": "./assets/notif-icon.png",
"color": "#fff"
},
我也有完全一样的问题。 遵循文档,但没有图标显示,即使在构建时也是如此。
我也无法在 Android 上显示通知 - 我只在状态栏/托盘中获得更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.