react兼容safari9,ReactJS - FCM无法在safari浏览器中运行

I am trying to implement FCM push notification in my ReactJS application.

It is working in chrome and firefox browser perfectly but facing in an issue in safari browser.

FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser).

I also gone through the documentation of firebase also found that it only supports on only 3 browsers.

Chrome

Firefox

Safari

Is there any method to supports in safari browser as well.

解决方案

Safari 11.1 already supported serviceWorker, but it still didn't support PushAPI that is also needed by FCM Javascript API.

The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API.

Here is the supported browser list: https://caniuse.com/#feat=push-api that states that Safari still not supporting Push API

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在浏览器运行 React Native 项目,需要使用 React Native Web。这是一个使 React Native 应用程序可以在 Web 上运行的库。 以下是在浏览器运行 React Native 项目的步骤: 1. 在项目安装 react-native-web: ``` npm install react-native-web ``` 2. 修改项目的入口文件,将其从 index.js 改为 index.web.js,然后从 react-native 和 react-native-web 导入 AppRegistry 和组件。 3. 创建一个名为 index.html 的新文件,并将以下内容添加到其: ``` <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>My React Native App</title> </head> <body> <div id="root"></div> <script src="./index.web.js"></script> </body> </html> ``` 这将创建一个包含一个 id 为 root 的 div 元素的 HTML 文件,并将 index.web.js 作为脚本包含在内。 4. 在项目根目录创建一个名为 webpack.config.js 的新文件,并将以下内容添加到其: ``` const path = require('path'); const webpack = require('webpack'); module.exports = { entry: './index.web.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, module: { rules: [ { test: /\.(js|jsx)$/, exclude: /node_modules/, use: { loader: 'babel-loader', }, }, { test: /\.(png|jpe?g|gif)$/i, use: [ { loader: 'file-loader', }, ], }, ], }, plugins: [ new webpack.DefinePlugin({ __DEV__: JSON.stringify(true), }), ], }; ``` 这将创建一个名为 bundle.js 的文件,其包含打包后的 React Native 代码。 5. 安装 webpack 和 webpack-dev-server: ``` npm install webpack webpack-dev-server --save-dev ``` 6. 在 package.json 文件添加以下内容: ``` "scripts": { "start": "webpack-dev-server --hot --open", "build": "webpack" } ``` 这将允许您使用 npm start 命令启动开发服务器,并使用 npm run build 命令构建项目。 7. 运行项目: ``` npm start ``` 运行此命令后,浏览器将自动打开,并在其显示 React Native 应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值