推送通知可以很好地加载到我的iOS手机上。我可以获取令牌,并成功地将其保存到我的Google Firestore数据库中,并从其中调用它。调用它来发送通知也可以像预期的那样工作。如果我不在应用程序中,我会收到通知。如果我在应用程序中,我的通知侦听器工作正常。
在构建到iOS并将独立应用程序部署到苹果服务器上的TestFlight之后,推送通知不再起作用。
这是我的版本。
Adrians-MBP:xxxxx abarthol$ expo build:ios -c
Checking if there is a build in progress...
Removed existing credentials from expo servers
Please enter your Apple Developer Program account credentials. These
credentials are needed to manage certificates, keys and provisioning profiles
in your Apple Developer account.
The password is only used to authenticate with Apple and never stored.
? Apple ID: xxxxx
? Password (for xxxxx): [hidden]
Trying to authenticate with Apple Developer Portal...
Authenticated with Apple Developer Portal successfully!
Only 1 team associated with your account, using Apple Team with ID: xxxxx
We do not have some credentials for you: Apple Distribution Certificate, Apple Push Notifications service key, Apple Provisioning Profile
? How would you like to upload your credentials? Expo handles all credentials, y
ou can still provide overrides
? Will you provide your own Apple Distribution Certificate? Let Expo handle the
process
✔ Didn't find any previously uploaded Apple Distribution Certificate
? Will you provide your own Apple Push Notifications service key? I want to uplo
ad my own file
Please provide your Apple Push Notifications service key:
? Path to P8 file: ~/Sites/certs/aps.cer
? Key ID: xxxxx
✔ App ID found on Apple Developer Portal.
We're going to generate:
- Apple Distribution Certificate
- Apple Provisioning Profile
✔ Generated Apple Distribution Certificate
✔ Generated Apple Provisioning Profile
Encrypted credentials and saved to the Expo servers
Publishing to channel 'default'...
Building iOS bundle
Building Android bundle
Analyzing assets
Uploading assets
No assets changed, skipped.
Processing asset bundle patterns:
- ~/Sites/Personal/xxxxx/**/*
Uploading JavaScript bundles
Published
Your URL is
https://exp.host/@xxxxx/xxxxx
Checking if this build already exists...
Build started, it may take a few minutes to complete.
You can check the queue length at https://expo.io/turtle-status
You can monitor the build at
https://expo.io/builds/xxxxx
Waiting for build to complete. You can press Ctrl+C to exit.
✔ Build finished.
Successfully built standalone app: https://expo.io/artifacts/xxxxx下面是我的组件:
componentDidMount() {
this.registerForPushNotifications();
}
componentWillUnmount() {
if (!this.subscription) return;
this.subscription.remove();
}
registerForPushNotifications = async () => {
const PNToken = await this.props.MainStore.getLocal("PNToken");
if (!PNToken) {
try {
const { status } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = status;
if (status !== "granted") {
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
if (finalStatus !== "granted") {
throw "Notification permission not granted";
}
const token = await Notifications.getExpoPushTokenAsync();
this.props.MainStore.setPNToken(token);
this.subscription = Notifications.addListener(
this.handleNotification
);
}
} catch (err) {
console.warn("Permissions check error: ", err);
}
} else {
this.props.MainStore.setPNToken(PNToken);
this.subscription = Notifications.addListener(this.handleNotification);
}
};
handleNotification = notification => {
const store = this.props.NotificationStore;
const sortedNotifications = sortMessages([
...store.state.notifications,
{ ...notification, read: false }
]);
store.setState({
notifications: sortedNotifications
});
};发布于 2019-08-25 07:07:13
我对push最终解决了这个问题有很多挫败感。1)在开发者门户>证书、标识符和配置文件>(您的应用程序的)标识符中启用推送通知2)按照此处所述创建您的P8密钥文件https://fluffy.es/p8-push-notification/ 3)删除现有配置配置文件4) expo构建:ios --clear-credentials,将您的APNS文件上传到expo
发布于 2019-07-08 18:11:03
从外观上看,当世博会要求新的P8格式时,您是在向世博会提供旧的APNS证书。
您应该能够从苹果会员中心生成一个新的P8文件。
发布于 2021-04-28 00:25:21
除了在expo.io上拥有正确的“苹果分发证书”、“苹果供应文件”和“苹果推送密钥”外,你还必须拥有正确的设备令牌。
首先,通过执行expo credentials:manager找到你的应用程序的experienceId。它显示为:@user/slug,包标识符: com.xxx.xxx
然后获取您的令牌,如下所示
const token = (
await Notifications.getExpoPushTokenAsync({
experienceId: '@user/slug', // <-- Experience shown above
})
).data;
console.log('EXPO TOKEN: ', token); // Store this in the backend将此设备令牌放入expo测试工具(https://expo.io/notifications)中,看看是否收到通知。
https://stackoverflow.com/questions/56925597
复制相似问题