简体   繁体   English

无需第三方服务即可同步移动应用和Web应用

[英]Sync Mobile App and Web App without third party services

Currently building a hybrid app. 目前正在构建一个混合应用 using Ionic Framework with PHP for backend services 使用Ionic FrameworkPHP进行后端服务

I am having a case where a user has got his profile in Web app and Mobile App as well. 我有一个案例,用户在Web应用程序和移动应用程序中也获得了他的个人资料。

If the user adds two stories as favourites (Its kind of a reading app) from his mobile app or Web app,how do I sync that? 如果用户从他的移动应用程序或Web应用程序添加两个故事作为收藏(它的阅读应用程序) ,我该如何同步?

Here are the scenarios: 以下是场景:

1) User marks the stories favourites from web app and when I come online through mobile app, display it. 1)用户通过网络应用标记故事收藏,当我通过移动应用程序上网时,显示它。

2) User marks the stories favourites from mobile app when he is offline (Now this will be stored in LocalDB ). 2)用户在离线时从移动应用程序标记故事收藏(现在这将存储在LocalDB中 )。 So again when he comes online sync with the server? 那么当他与服务器进行在线同步时呢?

I know there are services like Firebase which provides syncing service . 我知道有像Firebase这样的syncing service提供syncing service

But What If I would want to develop a Custom Syncing service on my own for my application? 但是如果我想为我的应用程序自己开发自定义同步服务呢? Is that an extremely complicated process? 这是一个非常复杂的过程吗?

If yes and it can be developed ,then how should I proceed ? 如果是,可以开发,那我该怎么办? A basic idea? 一个基本的想法? What are the best practices that I should consider? 我应该考虑哪些最佳实践?

Any links would be appreciated? 任何链接将不胜感激?

I know some of the comments recommended CouchDB in combination with PouchDB. 我知道一些评论建议将CouchDB与PouchDB结合使用。 That is a much better solution than trying to implement your own synchronization service with MySQL. 这比尝试使用MySQL实现自己的同步服务要好得多。

However, since you're using Ionic Framework you can also use Couchbase. 但是,由于您使用的是Ionic Framework,因此您也可以使用Couchbase。 Take the following example application: 采用以下示例应用程序:

https://github.com/couchbaselabs/TodoLite-Ionic https://github.com/couchbaselabs/TodoLite-Ionic

If you chose this solution you would have three moving parts. 如果您选择此解决方案,您将拥有三个活动部件。 You would be replacing MySQL with Couchbase Server and running the Couchbase Sync Gateway to orchestrate any data between the device and the server. 您将使用Couchbase Server替换MySQL并运行Couchbase Sync Gateway来协调设备和服务器之间的任何数据。 You can still keep your PHP backend if you have a web version of your application as there is a PHP SDK for Couchbase. 如果你有一个Web应用程序的版本,你仍然可以保留你的PHP后端,因为有一个用于Couchbase的PHP SDK。

Two write-ups on this can be found here: 关于此的两篇报道可以在这里找到:

http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-1 http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-2 http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-1 http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application -第2部分

In the long term, you're going to find NoSQL much more pleasant to work with when it comes to APIs and mobile than MySQL. 从长远来看,当涉及到API和移动设备时,你会发现NoSQL比MySQL更令人愉快。

Can be useful to write a POST method on the backend that receives the data from your local from the app and some user data (session, access tokens and other thing you considered neceasary). 在后端编写POST方法可以很有用,该方法从应用程序和本地接收来自本地的数据和一些用户数据(会话,访问令牌和其他您认为是必需的东西)。 On the body for the request you include the data needed to be synced. 在请求的正文中,您包含了需要同步的数据。 The backend takes the body. 后端占据了身体。 Parse it and rreturn a result (http code) Based on that you can decide if the app should delete the local data or only mark it as synced on the local database 解析它并返回结果(http代码)基于此,您可以决定应用程序是应该删除本地数据还是仅将其标记为在本地数据库上同步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM