简体   繁体   English

2022年如何处理expo推送通知图标?

[英]How to handle expo push notification icon in 2022?

As per documentation all you need to do is set some keys in app.json根据文档,您需要做的就是在 app.json 中设置一些键

In the managed workflow, set your notification.icon and notification.color keys in app.json, rebuild your app, and you're good to go!在托管工作流程中,在 app.json 中设置您的 notification.icon 和 notification.color 键,重新构建您的应用程序,一切顺利!

For bare workflow and EAS Build users you need to configure plugins section:对于裸工作流和 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"
          ]
        }
      ]
    ]

The only problem is that none of those solutions works, I thought that maybe the problem is with the icon because the docs also says that:唯一的问题是这些解决方案都不起作用,我认为问题可能出在图标上,因为文档还说:

For your notification icon, make sure you follow Google's design guidelines (the icon must be all white with a transparent background) or else it may not be displayed as intended.对于您的通知图标,请确保您遵循 Google 的设计指南(图标必须全白,背景透明),否则可能无法按预期显示。

So I have tried with the standard expo adaptive-icon.png that is in the assets folder which is different than expo logo shown as the icon in the push notification but no, it did not work as well.因此,我尝试使用资产文件夹中的标准 expoadaptive-icon.png 与推送通知中显示为图标的 expo 徽标不同,但不,它也不起作用。 Can someone please tell me how to do it?有人可以告诉我该怎么做吗? This is my app.json这是我的应用程序。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": []
        }
      ]
    ]
  }
}

I have also tried to change the color in the schedulePushNotification handler in the component like so:我还尝试更改组件中 schedulePushNotification 处理程序的颜色,如下所示:

  async function schedulePushNotification() {
    await Notifications.scheduleNotificationAsync({
      content: {
        autoDismiss: false,
        color: "#AEDE2D",
        title: "hey",
        body: "hello",
        data: { data: "goes here" },
      },
      trigger: { seconds: 3 },
    });
  }

And despite I have set autoDismiss to false is disappears after a few seconds and id did not take the requested color.尽管我已将 autoDismiss 设置为 false,但几秒钟后它就会消失,并且 id 没有采用请求的颜色。 In my App.tsx above the component definition I have a function在组件定义上方的 App.tsx 中,我有一个 function

Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: true,
  }),
});

like they are showing in the docs https://docs.expo.dev/versions/latest/sdk/notifications/ and than in the component i do import * as Notifications from "expo-notifications";就像他们在文档https://docs.expo.dev/versions/latest/sdk/notifications/中显示的那样,而不是在组件中我确实导入 * 作为来自“expo-notifications”的通知; and I use it in the schedulePushNotification handler above, does it make a call to this same object?我在上面的 schedulePushNotification 处理程序中使用它,它是否调用了同一个 object?

  1. Create a compatible icon here . 在此处创建兼容图标。
  2. Put it in your assets folder.把它放在你的资产文件夹中。
  3. Edit app.json编辑 app.json
"notification": {
 "icon": "./assets/notif-icon.png",
 "color": "#fff"
},
  1. Build your app!构建您的应用程序!

I have exactly the same problem.我也有完全一样的问题。 Followed the docs, but no icon shows, even when built.遵循文档,但没有图标显示,即使在构建时也是如此。

I also cannot get the notification to display on Android - I only get an update in the statusbar/tray我也无法在 Android 上显示通知 - 我只在状态栏/托盘中获得更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM