"expo": "^39.0.0"
/ 图书馆 - 博览会通知。
自从迁移到新的 API 以来,我一直面临着各种问题。我修复了图标的问题,通过处理程序在 apk 中接收通知,现在我找不到这个问题的答案。
我有 3 部手机三星Galaxy S9+,小米红米 4x 和小米红Android 10
米Note 4 Global。Android 7.12 N2G47H MIUI 10 Global 9.6.27
Android 7.0 nrd90m MIUI global 11.0.2
三星盖乐世 S9+。使用我当前的配置,我会收到很好的通知,因为它应该是:
- 振动 +
- 声音 +
- 收到通知时弹出 +
所有这些都来自盒子,我不需要询问权限或类似的东西。
Xiaomi Redmi 4x 和 Xiaomi Redmi Note 4。使用我目前的配置,我遇到了问题:
- 振动 -不适用于已发布和 apk(独立)版本
- 声音 +
- 收到通知时弹出 +
和主要问题:所有这些都不是来自盒子,我需要手动授予弹出通知、声音等的权限。
我的 app.json :
{
"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;
};
另外,使用所有这些的地方:
useEffect(() => {
const handleNotification = async () => {
await getPermitsAndIntegrateIntoApp(store); // works great
};
const setPersistDataToStore = async () => {
const EXPO_PUSH_TOKEN = await registerForPushNotificationsAsync();
const qwertyyy = await getConfig(Constants.deviceId, EXPO_PUSH_TOKEN);
store.setQwerrt(config.destinations);
};
setPersistDataToStore();
Notifications.addNotificationReceivedListener(handleNotification);
return () => Notifications.removeAllNotificationListeners();
}, [store]);
在所有 3 部手机上,我都有处理通知的逻辑(发送请求、更新商店和我的应用程序上的更新屏幕)。它工作正常。
如何自动配置显示推送通知的权限?如何在小米上启用振动?