【问题标题】:Expo push notification not waking up lock screen on android世博会推送通知未在 android 上唤醒锁定屏幕
【发布时间】:2021-05-18 08:53:17
【问题描述】:

SDK 版本:41.0.1 平台(Android/iOS/web/all):Android

您好,我遇到了展会推送通知服务的问题。一切正常,但一件事,通知不会唤醒 android 设备的锁定屏幕。它适用于 ios。

我正在使用文档中的零食,这是我的代码:

NotificationProvider.TS

        React.useEffect(() => {
        if (!authContext.authState.isConnected) return;
        registerForPushNotificationsAsync().then((token) => setExpoPushToken(token));
        notificationListener.current = Notifications.addNotificationReceivedListener((notification) => {
          setNotification(notification);
        });
        responseListener.current = Notifications.addNotificationResponseReceivedListener((response) => {
          console.log(response);
        });
        return () => {
          Notifications.removeNotificationSubscription(notificationListener.current);
          Notifications.removeNotificationSubscription(responseListener.current);
        };
      }, [authContext.authState.isConnected]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

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

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

  if (Platform.OS === 'android') {
    await Notifications.setNotificationChannelAsync('Requêtes', {
      name: 'Requêtes',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
      lockscreenVisibility: Notifications.AndroidNotificationVisibility.PUBLIC,
      enableLights: true,
    });
  }

  return token;
}

在互联网上没有找到任何解决方案。有没有人遇到过同样的问题?

【问题讨论】:

    标签: react-native push-notification expo


    【解决方案1】:

    这是标准的android行为,要在收到通知时唤醒锁屏,用户需要在手机设置中手动启用此功能

    【讨论】:

    • 问题是:手机上没有这样的设置,还有像snapchat、insta之类的应用程序。没有启用任何东西的事情
    • @NicolasSerradid 你找到解决方案了吗?我有同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2022-06-19
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    相关资源
    最近更新 更多