在 Ionic 4 PWA 应用程序中使用什么进行存储?
What to use for storage in an Ionic 4 PWA app?
我正在使用 Ionic 4 构建 PWA。它应该只能在浏览器上工作(到目前为止)并且主要用于具有离线功能的移动设备。到目前为止,我一直在使用离子存储,它在桌面浏览器和我的 android 设备上运行良好。但是在 iPhone 上不行。我读到这是一个已知问题。所以我正在寻找一个实际上是跨平台的解决方案。有什么东西可以在 android、ios 和桌面浏览器上使用吗?
Cordova 不是解决方案,因为它不能在网络上运行。
我需要做的第一件事是在登录时存储访问令牌。从那里我想我就能弄明白了。
您可以尝试像 PouchDB 这样的数据库实现,它基本上是一个 CouchDB 适配器。开发者在他们的网站上解释:
PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.
PouchDB was created to help web developers build applications that work as well offline as they do online.
It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user's data in sync no matter where they next login.
在我公司的一个 Ionic 4 项目中,我们使用 PouchDB 来存储应用程序和 Web 使用(iOS 和浏览器)的数据。您可以选择 one of several suitable adapters 用于浏览器存储以及本机设备。
When running in the web or as a Progressive Web App, Storage will attempt to use IndexedDB, WebSQL, and localstorage, in that order.
离子存储将在 iOS 上正常工作。所有这三个存储引擎都将 运行 在 iOS 上的 Safari 中。如果 Ionic Storage 不工作,您应该向 Ionic 报告错误或提出有关让 Storage 工作的问题。
我正在使用 Ionic 4 构建 PWA。它应该只能在浏览器上工作(到目前为止)并且主要用于具有离线功能的移动设备。到目前为止,我一直在使用离子存储,它在桌面浏览器和我的 android 设备上运行良好。但是在 iPhone 上不行。我读到这是一个已知问题。所以我正在寻找一个实际上是跨平台的解决方案。有什么东西可以在 android、ios 和桌面浏览器上使用吗?
Cordova 不是解决方案,因为它不能在网络上运行。
我需要做的第一件事是在登录时存储访问令牌。从那里我想我就能弄明白了。
您可以尝试像 PouchDB 这样的数据库实现,它基本上是一个 CouchDB 适配器。开发者在他们的网站上解释:
PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.
PouchDB was created to help web developers build applications that work as well offline as they do online.
It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user's data in sync no matter where they next login.
在我公司的一个 Ionic 4 项目中,我们使用 PouchDB 来存储应用程序和 Web 使用(iOS 和浏览器)的数据。您可以选择 one of several suitable adapters 用于浏览器存储以及本机设备。
When running in the web or as a Progressive Web App, Storage will attempt to use IndexedDB, WebSQL, and localstorage, in that order.
离子存储将在 iOS 上正常工作。所有这三个存储引擎都将 运行 在 iOS 上的 Safari 中。如果 Ionic Storage 不工作,您应该向 Ionic 报告错误或提出有关让 Storage 工作的问题。