【发布时间】: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