我已经在我的项目中设置了react-native-onesignal以使用 OneSignal 实现推送通知。
自 Xcode 11.4 Beta 起,可以在 iOS 模拟器上测试推送通知。我创建了 JSON 格式的 apns 文件来测试模拟器上的推送通知,它工作得很好。
但是如何模拟 OneSignal 推送通知?
我关注了 OneSignal 文档并希望接收从 OneSignal 仪表板发送的推送通知。
这是我在 App.tsx 文件中实现的内容。
const initializeOneSignal = () => {
OneSignal.setLogLevel(6, 0);
OneSignal.init("MY_ONESIGNAL_APP_ID", {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: false,
kOSSettingsKeyInFocusDisplayOption: 2,
});
OneSignal.inFocusDisplaying(2);
OneSignal.promptForPushNotificationsWithUserResponse(myiOSPromptCallback);
OneSignal.addEventListener('received', onPNReceived);
OneSignal.addEventListener('opened', onPNOpened);
OneSignal.addEventListener('ids', onPNIds);
};
useEffect(() => {
initializeOneSignal();
return () => {
OneSignal.removeEventListener('received', onPNReceived);
OneSignal.removeEventListener('opened', onPNOpened);
OneSignal.removeEventListener('ids', onPNIds);
};
}, []);
const onPNReceived = notification => {
console.log('Notification received: ', notification);
};
const onPNOpened = openResult => {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult);
};
const onPNIds = device => {
console.log('Device info: ', device);
};
const myiOSPromptCallback = permissions => {
console.log('Permissions: ', permissions);
};
当我从 OneSignal 仪表板发送推送通知时,我看不到任何记录的消息。
我需要在 apns 文件中做任何技巧吗?
任何帮助,将不胜感激。