英文:
Unable to receive push notification send via Firebase console in iOS using React-Native-Firebase
问题
我已经尝试遵循这个指南https://rnfirebase.io/messaging/usage/ios-setup 来为我的React-Native应用程序设置推送通知。特别是,我已经完成了以下操作:
- 添加推送通知和后台模式功能(包括远程获取和后台活动)。
- 在Apple开发者帐户中注册一个带有APNs启用的密钥,并将其上传到Firebase控制台设置中,确保KeyID(在注册密钥时获取)和TeamID(从开发者会员详细信息中获取)正确。
- 注册应用程序标识符(带有APNs功能)。由于我的项目有两个包标识符 -
org.reactjs.native.example.AppName
和org.test.AppName
,我都尝试了但都不起作用。 - 注册一个Provisioning配置文件。我相信这会自动与我的Xcode同步。
我注意到在注册应用程序标识符之后,我可以进一步配置APNs功能,但指南中没有提到这一点,我也没有这样做:
> 要为此应用程序标识符配置推送通知,需要一个允许您的通知服务器连接到Apple推送通知服务的客户端SSL证书。每个应用程序标识符都需要其自己的客户端SSL证书。在下面管理和生成您的证书。
在我的React-Native应用程序中,我有以下代码:
const App => {
useEffect(() => {
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
requestPermission();
});
useEffect(() => {
async function getToken() {
await messaging().registerDeviceForRemoteMessages();
const token = await messaging().getToken();
console.log(token);
}
getToken();
});
...
}
在应用程序启动时接受通知权限请求后,这将输出FCM令牌,我将其用于在Firebase控制台中发送测试消息。
我有遗漏任何步骤吗?在首次在metro下运行的React-Native调试构建中发送推送通知是否可能?提前感谢您的回答。
英文:
I have tried to follow this guide https://rnfirebase.io/messaging/usage/ios-setup to set up push notifications for my React-Native application. In particular, I have done the following:
- Adding Push Notification & Background Mode capabilities(with Remote fetch and background activities)
- Register a key(with APNs enabled) in Apple developer account and upload it to firebase console settings with the correct KeyID(obtained when registering the key) and TeamID(obtained from developer's membership detail)
- Register the App Identifier(with APNs capability). Since there are two bundle Identifiers for my project -
org.reactjs.native.example.AppName
andorg.test.AppName
, I have tried both but none works. - Register a Provisioning profile. I believe this wil automatically sync with my Xcode.
I note that I can further configure the APNs capability after registering the App Identifier, but this is not mentioned in the guide and I didn't do that:
> To configure push notifications for this App ID, a Client SSL Certificate that allows your notification server to connect to the Apple Push Notification Service is required. Each App ID requires its own Client SSL Certificate. Manage and generate your certificates below.
In my React-Native application, I have the following code:
const App => {
useEffect(() => {
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
requestPermission();
});
useEffect(() => {
async function getToken() {
await messaging().registerDeviceForRemoteMessages();
const token = await messaging().getToken();
console.log(token);
}
getToken();
});
...
}
After accepting the notification permission request when the app launch. This will output the FCMs token, which I use to send a test message in the Firebase console.
Did I miss any steps? Is it possible to send push notifications in React-Native debug built running under metro in the first place? Thank you in advance.
答案1
得分: 1
我找到了问题。是因为我在XCode构建产品时使用了不同的捆绑标识(bundle ID),而在苹果开发者帐户中注册标识时使用了不同的标识。按照逐步的步骤编写的步骤确实有效。
英文:
I figured out the problem. It is because I used a different bundle ID when building the product in XCode and when registering the identifier in Apple Developer Account. The steps by steps does work as of writing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论