react-native - 使用托管工作流的 Expo 推送通知不起作用
问题描述
我不想在 expo 中创建我的新应用程序,并通过托管工作流程做出本机反应。我有一个付费的苹果开发者帐户,我的所有凭据都上传到我的 expo 帐户。iOS 和 Android 的构建运行良好。特别是我的 Apple Push Notification Service 密钥也已上传到 expo 帐户。但是当我尝试使用 Expo Notification Tool 发送通知时,我的手机没有收到任何信息。但是,如果我尝试使用 Expo Go 启动我的应用程序,它就可以工作。因此,在生产模式下,我的通知不起作用。但是我成功获得了我的 Expo Push 令牌,并且我发送通知的权限还可以。我按照此文档设置我的通知:https://docs.expo.dev/push-notifications/push-notifications-setup/ 这是我在 App.js 中的代码:
async 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') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
return token;
}
_handleNotification = async notification => {
console.log(notification);
if (notification.remote) {
Vibration.vibrate();
const notificationId = Notifications.presentLocalNotificationAsync({
title: "Follow @technoplato",
body: "To learn yourself goodly (also follow PewDiePie)",
ios: { _displayInForeground: true }
});
}
this.setState({ notification: notification });
};
_handleNotificationResponse = response => {
console.log(response);
};
componentDidMount() {
this.registerForPushNotificationsAsync().then(token => {
this.setState({expoPushToken: token})
alert('Push Token: ' + token);
});
Notifications.addNotificationReceivedListener(this._handleNotification);
Notifications.addNotificationResponseReceivedListener(this._handleNotificationResponse);
}
这是我的 app.json :
{
"expo": {
"name": "Spirit",
"slug": "spirit-app",
"version": "1.0.2",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": false,
"bundleIdentifier": "com.ml-dev.spirit.app"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.ml.dev.spirit.app"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
你有什么想法导致这个问题吗?
解决方案
推荐阅读
- sql - SQL Server 作业完成后如何触发 DataStage 作业?
- excel - 找不到方法或数据成员(编译错误)
- ibm-cloud - Watson 机器学习部署需要太多时间
- oracle - 使用 SQL Developer 连接到 Oracle 数据库在 Windows 上有效,但在 Ubuntu 上无效
- dart - 当 ExpansionTile 在 Flutter 中崩溃时,ExpansionTile 内的 TextFormField 会丢失数据
- python - 寻找 Flask 的 request.get_data() 的 Django 等效项(用于使用原始请求正文进行 Slack 请求验证)
- python-3.x - 将属性“键”添加到连接的数据帧
- python - 如何使用 python 从 azure aks 获取 kubectl 配置?
- c# - AuthenticationHeaderValue:.NET CORE 上的 SharedAccessSignature
- continuous-integration - 带有 XUnit 的 dotMemory Unit Standalone 启动器在测试结束时挂起