世博会通知不会弹出

时间:2020-11-02 13:12:02

标签: android push-notification notifications expo expo-notifications

"expo": "^39.0.0" /库-博览会通知。

自从使用新API以来,我一直面临各种问题。我修复了图标的问题,通过apk接收通知,使用处理程序,现在我找不到该问题的答案。

我有3部手机,其中{em> Samsung Galaxy S9 + Android 10 小米Redmi 4x 和{ {1}}和 Xiaomi Redmi Note 4 Global Android 7.12 N2G47H MIUI 10 Global 9.6.27

三星Galaxy S9 +。使用我当前的配置,我会收到通知 应该很棒:

  • 振动+
  • 声音+
  • 通知到达时弹出窗口+

所有这些都是从框中输入的,我不需要询问权限之类的东西。

小米Redmi 4x和小米Redmi Note 4。 使用我当前的配置,我遇到了问题:

  • 振动-在已发布版本和apk(独立)版本中均不起作用
  • 声音+
  • 通知到达时弹出窗口+

主要问题:这一切都不是从盒子里来的,我需要手动授予弹出,声音等通知的权限。

我的app.json:

Android 7.0 nrd90m MIUI global 11.0.2

我的权限/配置:

{
  "expo": {
    "name": "qwert",
    "slug": "qwert",
    "version": "1.1.2",
    "orientation": "portrait",
    "icon": "./src/assets/images/logo1024.png",
    "scheme": "myapp",
    "userInterfaceStyle": "automatic",
    "privacy": "unlisted",
    "splash": {
      "image": "./src/assets/images/splashScreen.png",
      "resizeMode": "contain",
      "backgroundColor": "#f1f0f0"
    },
    "android": {
      "package": "com.qwert.app",
      "googleServicesFile": "./google-services.json",
      "versionCode": 1,
      "useNextNotificationsApi": true
    },
    "notification": {
      "icon": "./src/assets/images/VIAicon96.png",
      "color": "#8edcd5",
      "androidMode": "collapse"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "web": {
      "favicon": "./assets/images/favicon.png"
    },
    "description": ""
  }
}

还要在所有使用这些地方:

import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
import { Platform } from 'react-native';

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

export const registerForPushNotificationsAsync = async () => {
  let token;
  if (Constants.isDevice) {
    const { status: existingStatus } = await Permissions.getAsync(
      Permissions.NOTIFICATIONS,
    );
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      console.log('Failed to get push token for push notification!');
      return;
    }
    token = (await Notifications.getExpoPushTokenAsync()).data;
    console.log(token);
  } else {
    console.log('Must use physical device for Push Notifications');
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
    });
  }
  // eslint-disable-next-line consistent-return
  return token;
};

在所有3部手机上,我都有处理通知的逻辑(我的应用程序上具有发送请求,更新存储和更新屏幕)。正确。

如何自动配置显示推送通知的权限?如何在小米上启用振动?

1 个答案:

答案 0 :(得分:0)

最后我找到了答案。 https://github.com/expo/expo/issues/8556告诉我们enter image description here 然后 Permissions.askAsync not working as expected告诉我们如何让用户设置通知权限。

我仍然不知道为什么小米不振动......