sev*_*ven 6 android push-notification ios react-native expo
根据文档,您需要做的就是在 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"
]
}
]
]
Run Code Online (Sandbox Code Playgroud)
唯一的问题是这些解决方案都不起作用,我认为问题可能出在图标上,因为文档还说:
对于您的通知图标,请确保遵循 Google 的设计指南(图标必须为全白色且背景透明),否则可能无法按预期显示。
因此,我尝试使用资产文件夹中的标准 expo Adaptive-icon.png,它与推送通知中显示为图标的 expo 徽标不同,但它不起作用。有人可以告诉我该怎么做吗?这是我的 app.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": []
}
]
]
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试更改组件中的 SchedulePushNotification 处理程序中的颜色,如下所示:
async function schedulePushNotification() {
await Notifications.scheduleNotificationAsync({
content: {
autoDismiss: false,
color: "#AEDE2D",
title: "hey",
body: "hello",
data: { data: "goes here" },
},
trigger: { seconds: 3 },
});
}
Run Code Online (Sandbox Code Playgroud)
尽管我已将 autoDismiss 设置为 false,但它会在几秒钟后消失,并且 id 没有采用请求的颜色。在组件定义上方的 App.tsx 中,我有一个函数
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
Run Code Online (Sandbox Code Playgroud)
就像它们在文档https://docs.expo.dev/versions/latest/sdk/notifications/中显示的那样,而不是在组件中我导入 * 作为来自“expo-notifications”的通知;我在上面的 SchedulePushNotification 处理程序中使用它,它是否调用同一个对象?
"icon"
和"color"
放在插件部分)"expo": {
...
"notification": {
"icon": "./assets/notif-icon.png",
"color": "#fff"
},
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3307 次 |
最近记录: |