世博会。通知不弹出
EXPO. Notifications do not popup
"expo": "^39.0.0"
/图书馆 - 博览会通知。
自从搬到新 API 后,我一直面临着各种问题。我修复了图标问题,在 apk 中接收通知,处理程序,现在我找不到这个问题的答案。
我有 3 部手机 Samsung Galaxy S9+ Android 10
, 小米Redmi 4x with Android 7.12 N2G47H MIUI 10 Global 9.6.27
and Xiaomi Redmi Note 4 Global Android 7.0 nrd90m MIUI global 11.0.2
.
三星 Galaxy S9+。使用我当前的配置,我收到通知
应有的优秀:
- 振动 +
- 声音+
- 收到通知时弹出 +
所有这些都来自盒子,我不需要询问权限或类似的东西。
小米红米4x和小米红米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": ""
}
}
我的permissions/configs:
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 部手机上,我都有处理通知的逻辑(在我的应用程序上发送请求、更新存储和更新屏幕)。它工作正常。
如何自动配置显示推送通知的权限?小米如何开启震动?
终于找到答案了。
https://github.com/expo/expo/issues/8556 tells us that
然后
Permissions.askAsync not working as expected 告诉我们如何让用户设置通知权限。
而且我还不知道为什么小米不震动......
我有小米 Redmi 6A,使用 Expo 文档中示例的默认配置,我只收到振动通知。我必须手动打开默认频道的弹出(浮动)和声音。只有在通知开始按预期工作之后。
"expo": "^39.0.0"
/图书馆 - 博览会通知。
自从搬到新 API 后,我一直面临着各种问题。我修复了图标问题,在 apk 中接收通知,处理程序,现在我找不到这个问题的答案。
我有 3 部手机 Samsung Galaxy S9+ Android 10
, 小米Redmi 4x with Android 7.12 N2G47H MIUI 10 Global 9.6.27
and Xiaomi Redmi Note 4 Global Android 7.0 nrd90m MIUI global 11.0.2
.
三星 Galaxy S9+。使用我当前的配置,我收到通知 应有的优秀:
- 振动 +
- 声音+
- 收到通知时弹出 +
所有这些都来自盒子,我不需要询问权限或类似的东西。
小米红米4x和小米红米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": ""
}
}
我的permissions/configs:
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 部手机上,我都有处理通知的逻辑(在我的应用程序上发送请求、更新存储和更新屏幕)。它工作正常。
如何自动配置显示推送通知的权限?小米如何开启震动?
终于找到答案了。
https://github.com/expo/expo/issues/8556 tells us that
而且我还不知道为什么小米不震动......
我有小米 Redmi 6A,使用 Expo 文档中示例的默认配置,我只收到振动通知。我必须手动打开默认频道的弹出(浮动)和声音。只有在通知开始按预期工作之后。