[英]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.